首页 > 解决方案 > #ifndef 错误:需要更新包含路径

问题描述

我的头文件“broker.h”是

#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

#ifndef BROKER中出现错误,因为“存在 #include 错误。请更新 includePath。”

我的 c_cpp_properties.json 是

在此处输入图像描述

我的项目文件夹位置是

在此处输入图像描述

但是,我的包含路径是正确的,当我只是一个简单的 HelloWorld.cpp 时没有错误。为什么#ifndef 中有错误?

标签: c++visual-studio-codeifndef

解决方案


推荐阅读