summaryrefslogtreecommitdiffstats
path: root/Master/Modellbildung_und_Simulation/Aufgabenblatt2/Aufgabe2und3/src/Parametrisation.h
blob: 337442ee881590bda4a9a37ab4c7557af361657d (plain)
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
/*
 * Parametrisation.h
 *
 *  Created on: 13.05.2011
 *      Author: sven
 */

#ifndef PARAMETRISATION_H_
#define PARAMETRISATION_H_

#include <vector>
#include <map>
#include <string>

enum enCompany
{
	nenDaimler = 0,
	nenDeuBa,
	nenFMC,
	nenRWE,
	nenSolarWorld,

	// must be last entry
	nenEndOfCompanies
};

enum enHoldingTime
{
	nenOneDay = 1,
	nenTenDays = 10
};

struct Stock
{
	double mValue;
	double mValueRelChangeOne;
	double mValueRelChangeTen;
	Stock()
	:mValue(-99999999.9),mValueRelChangeOne(-99999999.9),mValueRelChangeTen(-99999999.9)
	{}
	void calcRelChange(const Stock& prev, const enHoldingTime& holdingTime)
	{
		switch (holdingTime)
		{
		case nenOneDay:
			mValueRelChangeOne = ((mValue - prev.mValue) / prev.mValue) * 100.0;
			break;
		case nenTenDays:
			mValueRelChangeTen = ((mValue - prev.mValue) / prev.mValue) * 100.0;
			break;
		default:
			break;
		}

	}
};

struct StockPrices
{
	StockPrices()
	:mStock(nenEndOfCompanies) {}
	std::string mDate;
	unsigned mDayIdx;
	std::vector<Stock> mStock;
	void calcRelChanges(const StockPrices& prevDay, const enHoldingTime& holdingTime)
	{
		for (unsigned c = static_cast<unsigned>(nenDaimler) ; c < static_cast<unsigned>(nenEndOfCompanies); c++) {
			mStock.at(c).calcRelChange(prevDay.mStock.at(c), holdingTime);
		}
	}
};


struct ArithAverages{
	double mArithAverOneDay;
	double mArithAverTenDays;
	ArithAverages()
	:mArithAverOneDay(0.0),mArithAverTenDays(0.0) {}
};


typedef std::vector< std::vector<double> > CovarianceMatrix;
typedef CovarianceMatrix CorrelationMatrix;


class Parametrisation {
public:
	Parametrisation();
	virtual ~Parametrisation();
	void readCsvFile();
	void calcRelChanges(const enHoldingTime& holdingTime);
	void calcArithAverageVectors();
	void calcCovarianceMatrices();
	void calcCorrelationMatrices();

	double getLastValue(const enCompany& comp) const
	{
		return mLastYearData.back().mStock.at(comp).mValue;
	}

	const CovarianceMatrix& getCovarianceMatrix(const enHoldingTime& holdingTime) const
	{
		switch (holdingTime)
		{
		case nenOneDay:
			//return mCorrelationMatrixOneDay;
			return mCovarinaceMatrixOneDay;
		case nenTenDays:
			//return mCorrelationMatrixTenDays;
			return mCovarinaceMatrixTenDays;
		default:
			throw 17 ;
		}
	}
	void getArithAverages(std::vector<double>& mu, const enHoldingTime holdingTime) const
	{
		unsigned c;
		switch(holdingTime)
		{
		case nenOneDay:
			for (c = nenDaimler; c < nenEndOfCompanies; c++)
			{
				mu.at(c) = mArithAverageVectors.at(c).mArithAverOneDay;
			}
			return;
		case nenTenDays:
			for (c = nenDaimler; c < nenEndOfCompanies; c++)
			{
				mu.at(c) = mArithAverageVectors.at(c).mArithAverTenDays;
			}
			return;
		default:
			throw 17;
		}
	}
	const std::vector<StockPrices>& getStockPrices() const
		{
		return mLastYearData;
		}
private:
	const static char* msInputFilename;
	std::vector< StockPrices > mLastYearData;
	std::vector<ArithAverages> mArithAverageVectors;
	std::vector<double> mStandardDeviationsOneDay;
	std::vector<double> mStandardDeviationsTenDays;
	CovarianceMatrix mCovarinaceMatrixOneDay;
	CovarianceMatrix mCovarinaceMatrixTenDays;
	CorrelationMatrix mCorrelationMatrixOneDay;
	CorrelationMatrix mCorrelationMatrixTenDays;

	void tokenize(const std::string& str, std::vector<std::string>& tokens, const std::string& delimiters = ";");
	double toDouble(const std::string& str);
	void dumpValues();
	void dumpRelChanges(const enHoldingTime& holdingTime);
	void dumpArithAverageVectors();
	void dumpCovarianceMatrices();
	void dumpCorrelationMatrices();
};

#endif /* PARAMETRISATION_H_ */