-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
91 lines (80 loc) · 2.79 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
//
// main.cpp
// Exercise1
//
// Created by 李美漉 on 2020/6/2.
// Copyright © 2020 NYU. All rights reserved.
//
#include <stdio.h>
#include <fstream>
#include <stdlib.h>
#include <sstream>
#include "csv.hpp"
#include "Matrix.hpp"
#include "readData.hpp"
#include "assetsReturns.hpp"
using namespace std;
int main() {
remove("results.csv");
// srand(time(NULL));
int numberAssets=83;
int numberReturns=700;
Matrix returnMatrix; // a matrix to store the return data
returnMatrix.resize(numberReturns);
for(int i=0;i<numberReturns;i++)
returnMatrix[i].resize(numberAssets);
string fileName="asset_returns.csv";
readData(returnMatrix,fileName);
double temp[] = {0.005, 0.01, 0.015, 0.02, 0.025, 0.03, 0.035, 0.04, 0.045, 0.05,
0.055, 0.06, 0.065, 0.07, 0.075, 0.08, 0.085, 0.09, 0.095, 0.1};
Vector tReturns(temp, temp + 20);
int isWindow = 100;
int oosWindow = 12;
int rollingWindow = 12;
int rollingTimes = (int) (numberReturns - oosWindow - isWindow)/ rollingWindow + 1;
// FTSE onePort(isWindow, oosWindow, rollingWindow, returnMatrix, tReturns[0]);
//
// onePort.calOosMean();
// onePort.calOosCovariance();
// onePort.calIsMean();
// onePort.calIsCovariance();
// onePort.calIsQ();
// double epsilon = 0.000001;
// onePort.weightSolver(epsilon);
// onePort.backtest();
//
// Vector actAvgReturn = onePort.getActAvgReturn();
// cout << actAvgReturn << endl;
vector<FTSE> portfolios;
Vector x;
double epsilon = 0.000001;
ofstream myfile;
myfile.open ("results.csv");
myfile << "Target return,";
for (int k = 0; k < rollingTimes-1; k++){
myfile << k+1 << ",";
}
myfile << rollingTimes << endl;
for (int i = 0; i < 20; i++){
cout << "Initialize portfolio with target return " << tReturns[i] << endl;
FTSE onePort(isWindow, oosWindow, rollingWindow, returnMatrix, tReturns[i]);
onePort.calOosMean();
onePort.calOosCovariance();
onePort.calIsMean();
onePort.calIsCovariance();
onePort.calIsQ();
onePort.weightSolver(epsilon);
onePort.backtest();
portfolios.push_back(onePort);
cout << "For target return " << tReturns[i] <<", the actual return is: " << endl;
Vector actAvgReturn = onePort.getActAvgReturn();
cout << actAvgReturn;
cout << "Sharpe: " << onePort.getSharpe() << " AAR: " << onePort.getAAR() << " Std: " << onePort.getStd() << " CAAR: " << onePort.getCAAR() << endl << endl;
myfile << tReturns[i] << ",";
for (int j = 0; j < actAvgReturn.size()-1; j++){
myfile << actAvgReturn[j] << ",";
}
myfile << actAvgReturn[actAvgReturn.size()-1] << endl;
}
return 0;
}