0

My header file "broker.h" is

#ifndef _BROKER_    
#define _BROKER_

#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <list>
#include <iterator>
#include <vector>
#include "strategy.h"
#include "utils.h"

using namespace std;

class Broker{
    private:
        vector< vector<double> > buy_signals; //time X codes
        vector< vector<double> > sell_signals; //time X codes
        vector< vector<double> > positions; //time X codes
        vector< vector<double> > cashs; //time X 1 
        vector< vector<double> > prices; // time X codes
        vector<double> position;
        
        fstream fs;
        fstream indi;
        
        vector<string>codes;
        vector<string>time_index;

        int n_cols, n_rows;
        double return_mean, sharp;
        Strategy strategy;

    public:
        double cash;
        double unit;
        
        template<typename T>
        void set_data(vector<string>& _codes, const map<string, vector<T>>>& _fs, const map<string, vector<T>>>& _indi, const vector<vector<double>>& _prices, const vector<string>& _time_index){
            codes = _codes;
            time_index = _time_index; //2015-2020
            n_cols = codes.size();
            n_rows = time_index.size();
            
            /*
            I don't know which data type is better for multi-index columns
            fs=_fs;
            indi = _indi;
            */

            buy_signals = zero_vector(buy_signals, n_rows, n_cols);
            sell_signals = zero_vector(sell_signals, n_rows, n_cols);
            positions = zero_vector(positions, n_rows, n_cols);
            cashs = zero_vector(cashs, n_rows, 1);
            prices = _prices;

            vector<vector<double>> temp;
            position = zero_vector(temp, 1, n_cols)[0];
        };

        void update_data(Strategy s, int date_index){
            cash = s.cash;
            position = s.position;

            cashs[i] = s.cash;  // times X 1 : vector< vector<int> >
            positions[i] = s.position; // times X codes : vector<vector<int>>
            buy_signals[i] = s.buy_signal;
            sell_signals[i] = s.sell_signal;
        };

        void run(){
            for (int i=0; i < n_rows ; i++) {
                string date = time_index[i];
                string year = date.substr(0,4);
                string prev_year = to_string(stoi(year)-1);

                // 추상적 데이터 접근 - fs 데이터 타입 정해진 후 수정 바람
                prev_fs_row = fs[prev_year]; // Not exact fs data type
                curr_fs_row = fs[year];
                curr_indi_row = indi[date];

                Strategy strat = Strategy();
                strat.set_data(prev_fs_row, curr_fs_row, curr_indi_row, codes, unit, cash);
                strat.run();
                update_data(strat, i);
            }
        };

        void performance(){
            vector<double> last_price = prices.back(); // {vector<int>, vector<int>, ....}
            vector<double> total_remain_num = position;

            vector<vector<double>> total_buy_data = d2_vec_mul(prices, buy_signals);
            vector<vector<double>> total_sell_data = d2_vec_mul(prices, sell_signals);
            double total_buy = sum_vector(sum_vector(total_buy_data, 1))[0][0];
            double total_sell = sum_vector(sum_vector(total_sell_data, 1))[0][0];
            double total_remain = vec_mul(last_price, total_remain_num)[0];
            
            double profit = total_sell + total_remain - total_buy;
            if (total_buy) {
                return_mean = profit/total_buy;
            }
            else{
                cout << "No buy!" <<endl;
                return;
            }
            
            int n_rows = time_index.size();
            // prices : already change from na -> 0 (from python)
            vector<vector<double>> posses_stock_value = sum_vector(d2_vec_mul(positions, prices), 1); // times X 1
            vector<vector<double>> accumulates = sum_vectors(cashs, posses_stock_value);
            vector<vector<double>> shift_accumulates = shift_vector(accumulates);
            vector<vector<double>> daily_return = divide_vectors(sum_vectors(accumulates, shift_accumulates, 0), shift_accumulates);
            vector<double> temp ={1}; vector<vector<double>> ones(n_rows, temp);
            daily_return = sum_vectors(daily_return, ones, 0);            
            temp.clear(); 
            
            temp.push_back(return_mean); vector<vector<double>> daily_return_mean(n_rows, temp); 
            vector<vector<double>> daily_Err = (sum_vectors(pop_front(daily_return), pop_front(daily_return_mean));
            double SSE = sum_vector(d2_vec_mul(daily_Err, daily_Err));
            double std = power_vector(SSE, 0.5);
            sharp = return_mean / std;  
        }
};

#endif

And there is an error in #ifndef BROKER as "There is #include error. Please update includePath."

My c_cpp_properties.json is

enter image description here

My project folder location is

enter image description here

However, my includepath is correct and when I just a simple HelloWorld.cpp there is no error. Why is there an error in #ifndef??

Alan Birtles
  • 32,622
  • 4
  • 31
  • 60
hyemin ju
  • 39
  • 6
  • What's the complete error message? Did you use the _BROKER_ define in one of the other headers as well? – MiniMik Oct 29 '21 at 05:19
  • This SO question might help you: https://stackoverflow.com/questions/51227662/vscode-include-errors-detected-please-update-your-includepath/57742056#57742056 – Daniel Oct 29 '21 at 06:44
  • Note that identifiers starting with underscore and a capital letter are reserved for the implementation. Don't use them. – molbdnilo Oct 29 '21 at 07:53
  • Maybe error occur in strategy.h or utils.h? and since broker.h incldue them, they also occur here? – Deumaudit Oct 29 '21 at 09:18
  • Actually there are same errors in all headers.. broker.h, preprocess.h, strategy.h, utils.h. – hyemin ju Oct 30 '21 at 06:35
  • utils.h does not contain other header, and I changed #ifndef UTILS -> #ifndef utils, it has error until now ;-( – hyemin ju Oct 30 '21 at 06:35
  • @MiniMik #include errors detected. Please update your includePath. Squiggles are disabled for this translation unit (C:\Users\hyemi\OneDrive\바탕 화면\Backtest\src\main.cpp).C/C++ – hyemin ju Oct 30 '21 at 06:39
  • Oh my god. after I rebuting my computer, the error has gone... – hyemin ju Oct 30 '21 at 06:43

0 Answers0