commit 62fbec9b44c5aff50c1f5b2838683232955a7f0c Author: Kacper Donat Date: Sun Mar 11 12:48:48 2018 +0100 initial commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..eb1a7ef --- /dev/null +++ b/.gitignore @@ -0,0 +1,40 @@ +*.csv +*.obj +*.exe +*.lst +*.tmp + +# tex +*.aux +*.lof +*.log +*.lot +*.fls +*.out +*.toc +*.fmt +*.fot +*.cb +*.cb2 +.*.lb +*.pdf + +## Build tool auxiliary files: +*.fdb_latexmk +*.synctex +*.synctex(busy) +*.synctex.gz +*.synctex.gz(busy) +*.pdfsync + +# hyperref +*.brf + +# listings +*.lol + +# makeidx +*.idx +*.ilg +*.ind +*.ist diff --git a/argh.h b/argh.h new file mode 100644 index 0000000..a17a76b --- /dev/null +++ b/argh.h @@ -0,0 +1,401 @@ +#pragma once + +#include +#include +#include +#include +#include +#include +#include + +namespace argh +{ + // Terminology: + // A command line is composed of 2 types of args: + // 1. Positional args, i.e. free standing values + // 2. Options: args beginning with '-'. We identify two kinds: + // 2.1: Flags: boolean options => (exist ? true : false) + // 2.2: Parameters: a name followed by a non-option value + +#if !defined(__GNUC__) || (__GNUC__ >= 5) + using string_stream = std::istringstream; +#else + // Until GCC 5, istringstream did not have a move constructor. + // stringstream_proxy is used instead, as a workaround. + class stringstream_proxy + { + public: + stringstream_proxy() = default; + + // Construct with a value. + stringstream_proxy(std::string const& value) : + stream_(value) + {} + + // Copy constructor. + stringstream_proxy(const stringstream_proxy& other) : + stream_(other.stream_.str()) + { + stream_.setstate(other.stream_.rdstate()); + } + + void setstate(std::ios_base::iostate state) { stream_.setstate(state); } + + // Stream out the value of the parameter. + // If the conversion was not possible, the stream will enter the fail state, + // and operator bool will return false. + template + stringstream_proxy& operator >> (T& thing) + { + stream_ >> thing; + return *this; + } + + + // Get the string value. + std::string str() const { return stream_.str(); } + + std::stringbuf* rdbuf() const { return stream_.rdbuf(); } + + // Check the state of the stream. + // False when the most recent stream operation failed + operator bool() const { return !!stream_; } + + ~stringstream_proxy() = default; + private: + std::istringstream stream_; + }; + using string_stream = stringstream_proxy; +#endif + + class parser + { + public: + enum Mode { PREFER_FLAG_FOR_UNREG_OPTION = 1 << 0, + PREFER_PARAM_FOR_UNREG_OPTION = 1 << 1, + NO_SPLIT_ON_EQUALSIGN = 1 << 2, + SINGLE_DASH_IS_MULTIFLAG = 1 << 3, + }; + + parser() = default; + + parser(std::initializer_list pre_reg_names) + { add_params(pre_reg_names); } + + parser(const char* const argv[], int mode = PREFER_FLAG_FOR_UNREG_OPTION) + { parse(argv, mode); } + + parser(int argc, const char* const argv[], int mode = PREFER_FLAG_FOR_UNREG_OPTION) + { parse(argc, argv, mode); } + + void add_param(std::string const& name); + void add_params(std::initializer_list init_list); + + void parse(const char* const argv[], int mode = PREFER_FLAG_FOR_UNREG_OPTION); + void parse(int argc, const char* const argv[], int mode = PREFER_FLAG_FOR_UNREG_OPTION); + + std::multiset const& flags() const { return flags_; } + std::map const& params() const { return params_; } + std::vector const& pos_args() const { return pos_args_; } + + // begin() and end() for using range-for over positional args. + std::vector::const_iterator begin() const { return pos_args_.cbegin(); } + std::vector::const_iterator end() const { return pos_args_.cend(); } + + ////////////////////////////////////////////////////////////////////////// + // Accessors + + // flag (boolean) accessors: return true if the flag appeared, otherwise false. + bool operator[](std::string const& name) const; + + // multiple flag (boolean) accessors: return true if at least one of the flag appeared, otherwise false. + bool operator[](std::initializer_list init_list) const; + + // returns positional arg string by order. Like argv[] but without the options + std::string const& operator[](size_t ind) const; + + // returns a std::istream that can be used to convert a positional arg to a typed value. + string_stream operator()(size_t ind) const; + + // same as above, but with a default value in case the arg is missing (index out of range). + template + string_stream operator()(size_t ind, T&& def_val) const; + + // parameter accessors, give a name get an std::istream that can be used to convert to a typed value. + // call .str() on result to get as string + string_stream operator()(std::string const& name) const; + + // accessor for a parameter with multiple names, give a list of names, get an std::istream that can be used to convert to a typed value. + // call .str() on result to get as string + // returns the first value in the list to be found. + string_stream operator()(std::initializer_list init_list) const; + + // same as above, but with a default value in case the param was missing. + // Non-string def_val types must have an operator<<() (output stream operator) + // If T only has an input stream operator, pass the string version of the type as in "3" instead of 3. + template + string_stream operator()(std::string const& name, T&& def_val) const; + + // same as above but for a list of names. returns the first value to be found. + template + string_stream operator()(std::initializer_list init_list, T&& def_val) const; + + private: + string_stream bad_stream() const; + std::string trim_leading_dashes(std::string const& name) const; + bool is_number(std::string const& arg) const; + bool is_option(std::string const& arg) const; + bool got_flag(std::string const& name) const; + + private: + std::vector args_; + std::map params_; + std::vector pos_args_; + std::multiset flags_; + std::set registeredParams_; + std::string empty_; + }; + + + ////////////////////////////////////////////////////////////////////////// + + inline void parser::parse(const char * const argv[], int mode) + { + int argc = 0; + for (auto argvp = argv; *argvp; ++argc, ++argvp); + parse(argc, argv, mode); + } + + ////////////////////////////////////////////////////////////////////////// + + inline void parser::parse(int argc, const char* const argv[], int mode /*= PREFER_FLAG_FOR_UNREG_OPTION*/) + { + // convert to strings + args_.resize(argc); + std::transform(argv, argv + argc, args_.begin(), [](const char* const arg) { return arg; }); + + // parse line + for (auto i = 0u; i < args_.size(); ++i) + { + if (!is_option(args_[i])) + { + pos_args_.emplace_back(args_[i]); + continue; + } + + auto name = trim_leading_dashes(args_[i]); + + if (!(mode & NO_SPLIT_ON_EQUALSIGN)) + { + auto equalPos = name.find('='); + if (equalPos != std::string::npos) + { + params_.insert({ name.substr(0, equalPos), name.substr(equalPos + 1) }); + continue; + } + } + + // if the option is unregistered and should be a multi-flag + if (1 == (args_[i].size() - name.size()) && // single dash + argh::parser::SINGLE_DASH_IS_MULTIFLAG & mode && // multi-flag mode + registeredParams_.find(name) == registeredParams_.end()) // unregistered + { + for (auto const& c : name) + { + flags_.emplace(std::string{ c }); + } + } + + // any potential option will get as its value the next arg, unless that arg is an option too + // in that case it will be determined a flag. + if (i == args_.size() - 1 || is_option(args_[i + 1])) + { + flags_.emplace(name); + continue; + } + + // if 'name' is a pre-registered option, then the next arg cannot be a free parameter to it is skipped + // otherwise we have 2 modes: + // PREFER_FLAG_FOR_UNREG_OPTION: a non-registered 'name' is determined a flag. + // The following value (the next arg) will be a free parameter. + // + // PREFER_PARAM_FOR_UNREG_OPTION: a non-registered 'name' is determined a parameter, the next arg + // will be the value of that option. + + if (registeredParams_.find(name) != registeredParams_.end() || + argh::parser::PREFER_PARAM_FOR_UNREG_OPTION & mode) + { + params_.insert({ name, args_[i + 1] }); + ++i; // skip next value, it is not a free parameter + continue; + } + + if (argh::parser::PREFER_FLAG_FOR_UNREG_OPTION & mode) + flags_.emplace(name); + }; + } + + ////////////////////////////////////////////////////////////////////////// + + inline string_stream parser::bad_stream() const + { + string_stream bad; + bad.setstate(std::ios_base::failbit); + return bad; + } + + ////////////////////////////////////////////////////////////////////////// + + inline bool parser::is_number(std::string const& arg) const + { + // inefficient but simple way to determine if a string is a number (which can start with a '-') + std::istringstream istr(arg); + double number; + istr >> number; + return !(istr.fail() || istr.bad()); + } + + ////////////////////////////////////////////////////////////////////////// + + inline bool parser::is_option(std::string const& arg) const + { + assert(0 != arg.size()); + if (is_number(arg)) + return false; + return '-' == arg[0]; + } + + ////////////////////////////////////////////////////////////////////////// + + inline std::string parser::trim_leading_dashes(std::string const& name) const + { + auto pos = name.find_first_not_of('-'); + return std::string::npos != pos ? name.substr(pos) : name; + } + + ////////////////////////////////////////////////////////////////////////// + + inline bool argh::parser::got_flag(std::string const& name) const + { + return flags_.end() != flags_.find(trim_leading_dashes(name)); + } + + ////////////////////////////////////////////////////////////////////////// + + inline bool parser::operator[](std::string const& name) const + { + return got_flag(name); + } + + ////////////////////////////////////////////////////////////////////////// + + inline bool parser::operator[](std::initializer_list init_list) const + { + return std::any_of(init_list.begin(), init_list.end(), [&](char const* const name) { return got_flag(name); }); + } + + ////////////////////////////////////////////////////////////////////////// + + inline std::string const& parser::operator[](size_t ind) const + { + if (ind < pos_args_.size()) + return pos_args_[ind]; + return empty_; + } + + ////////////////////////////////////////////////////////////////////////// + + inline string_stream parser::operator()(std::string const& name) const + { + auto optIt = params_.find(trim_leading_dashes(name)); + if (params_.end() != optIt) + return string_stream(optIt->second); + return bad_stream(); + } + + ////////////////////////////////////////////////////////////////////////// + + inline string_stream parser::operator()(std::initializer_list init_list) const + { + for (auto& name : init_list) + { + auto optIt = params_.find(trim_leading_dashes(name)); + if (params_.end() != optIt) + return string_stream(optIt->second); + } + return bad_stream(); + } + + ////////////////////////////////////////////////////////////////////////// + + template + string_stream parser::operator()(std::string const& name, T&& def_val) const + { + auto optIt = params_.find(trim_leading_dashes(name)); + if (params_.end() != optIt) + return string_stream(optIt->second); + + std::ostringstream ostr; + ostr << def_val; + return string_stream(ostr.str()); // use default + } + + ////////////////////////////////////////////////////////////////////////// + + // same as above but for a list of names. returns the first value to be found. + template + string_stream parser::operator()(std::initializer_list init_list, T&& def_val) const + { + for (auto& name : init_list) + { + auto optIt = params_.find(trim_leading_dashes(name)); + if (params_.end() != optIt) + return string_stream(optIt->second); + } + std::ostringstream ostr; + ostr << def_val; + return string_stream(ostr.str()); // use default + } + + ////////////////////////////////////////////////////////////////////////// + + inline string_stream parser::operator()(size_t ind) const + { + if (pos_args_.size() <= ind) + return bad_stream(); + + return string_stream(pos_args_[ind]); + } + + ////////////////////////////////////////////////////////////////////////// + + template + string_stream parser::operator()(size_t ind, T&& def_val) const + { + if (pos_args_.size() <= ind) + { + std::ostringstream ostr; + ostr << def_val; + return string_stream(ostr.str()); + } + + return string_stream(pos_args_[ind]); + } + + ////////////////////////////////////////////////////////////////////////// + + inline void parser::add_param(std::string const& name) + { + registeredParams_.insert(trim_leading_dashes(name)); + } + + ////////////////////////////////////////////////////////////////////////// + + inline void parser::add_params(std::initializer_list init_list) + { + for (auto& name : init_list) + registeredParams_.insert(trim_leading_dashes(name)); + } +} + + diff --git a/data/bitcoin.dat b/data/bitcoin.dat new file mode 100644 index 0000000..ec20b9f --- /dev/null +++ b/data/bitcoin.dat @@ -0,0 +1,684 @@ +8752.05 +8604.21 +8552.87 +8287.12 +8429.06 +8460.75 +8658.94 +8670.89 +8936.08 +8875.21 +8761.93 +9053.81 +9046.36 +9253.07 +9363.98 +9205.57 +9280.09 +9185.08 +9378.03 +9294.35 +9259.5 +9156.88 +9112.25 +9215.67 +9091.97 +8958.45 +9056.42 +9188.81 +9073.29 +9206.41 +9242.42 +9192.92 +9083.52 +8820.61 +8766.82 +8740.11 +8703.82 +8707.45 +8646.29 +8383.08 +8408.7 +8452.31 +8311.77 +8200.97 +8089.24 +8094.67 +8391.64 +8168.78 +8253.91 +8091.14 +8040.8 +8132.57 +8271.91 +8185.84 +8083.47 +7984.02 +7809.15 +7876.02 +7681.9 +7542.14 +7743.17 +7650.2 +7351.05 +7353 +7251.96 +7063.49 +6914.37 +6583.56 +7243.79 +7151.55 +6845.35 +6914.92 +6996.93 +6462.69 +6380.43 +6350.54 +6083.38 +6512.61 +6254.18 +5947.4 +6100.89 +6677.37 +6417.44 +6433.73 +6720.37 +7137.72 +7158.31 +7288.55 +7101.07 +6954.57 +7163.84 +7482.86 +7495.56 +7755.07 +7645.33 +7692.8 +7634.2 +7623.8 +7364.76 +7275.74 +7492.05 +7448.41 +7466.59 +7714.34 +7665.49 +7971.36 +8215.22 +8265.65 +8402.1 +8327.76 +8238.81 +8190.94 +7999.72 +8323.91 +8255.46 +8135.75 +8152.92 +8096.21 +7866.53 +7548.1 +7738.78 +7878.67 +8034.39 +8001.35 +8156.37 +8017.2 +8040.44 +8316.21 +8235.25 +8341.85 +8549.46 +8483.74 +8588.01 +8469.15 +8434.02 +8244.13 +8302.5 +8186.21 +8229.89 +8440.2 +8297.66 +8208.28 +8225.47 +8248.8 +7931.53 +7974.82 +8094.5 +8078.89 +7847.66 +7877.85 +7963.99 +8011.26 +8091.78 +8254.5 +8240.15 +8257.6 +8214.96 +8267.04 +8407 +8314.32 +8370.81 +8630.7 +8629 +8639.75 +8555.95 +8555.58 +8581.48 +8694.52 +8887.54 +8820.21 +8934.55 +8918.78 +8829.27 +8874 +9058.8 +8962.08 +8678.04 +8633.4 +8567.92 +8658.55 +8638.51 +8758.23 +8649.54 +8352.93 +8310.39 +8449.7 +8335.38 +8445.88 +8173.74 +8269.13 +8585.02 +8550.97 +8410.99 +8270.12 +8254.73 +8054.9 +7995.72 +8131.24 +8075.99 +7922.86 +7920.85 +8105.58 +8024.6 +8194.66 +8276.27 +8280.88 +8441.18 +8421.3 +8292.31 +8185.63 +8341.25 +8290.72 +8244.16 +8312.85 +8303.26 +8073.08 +8221 +8332.46 +8511.7 +8479.71 +8488.8 +8379.01 +8421.21 +8471.11 +8766.42 +8804.78 +8827.85 +8658.38 +8758.65 +8678.45 +8549.87 +8646.98 +8699.86 +8763.38 +8662.27 +8780.44 +8853.86 +8830.13 +8877.24 +8887.78 +8915.26 +8753.82 +8709.14 +8765.63 +8578.13 +8613.21 +8716.28 +8666.26 +8530.21 +8450.37 +8505.32 +8520.16 +8581.28 +8597.54 +8621.56 +8507.98 +8552.93 +8638.78 +8617.23 +8614.19 +8714.73 +8564.5 +8539.51 +8515.59 +8587.5 +8648.52 +8705.14 +8689.98 +8804.28 +8835.9 +8794.46 +8888.73 +8870.09 +8798.3 +8767.3 +8944.43 +9177.53 +9241.31 +9175.41 +9331.88 +9278.07 +9301.83 +9290.59 +9230.77 +9292.33 +9282.69 +9437.19 +9476.28 +9370.49 +9397.7 +9627.51 +9666.09 +9736.44 +9703.04 +9690.34 +9828.38 +9873.79 +9644.96 +9674.48 +9605.89 +9733.25 +9677.06 +9871.39 +9841.61 +9909.23 +10045.73 +10051.35 +10109.76 +10097.32 +9883.3 +10074.31 +10066.99 +10226.63 +10274.76 +10185.64 +10110.56 +9997.74 +10094.74 +9891.11 +9792.43 +9963.97 +9880.83 +9812.9 +9816.47 +9867.26 +9844.57 +10041.89 +10050.03 +10092.26 +10088.73 +9962.58 +10038.14 +9991.9 +10083.78 +10211.94 +10179.32 +10182.47 +10328.81 +10374.78 +10468.59 +10575.49 +10552.41 +10780.68 +10740.69 +10813.46 +10675.14 +10664.69 +10733.66 +10833 +10713.73 +10634.19 +10745.17 +10817.43 +10804.34 +10798.32 +10728.17 +10780.01 +10845.14 +10953.88 +11083.25 +11121.37 +11221.73 +11166.86 +10812.12 +10929.64 +10494.42 +10454.69 +10612.05 +10325.4 +10161.7 +10518.07 +10613.59 +10585.11 +10744.08 +10781.91 +10661.38 +10574.05 +10715.49 +10759.62 +10846.77 +10788.71 +10763.23 +10586.93 +10395.91 +10441.32 +10632.99 +10588.03 +10536.67 +10535.45 +10462.5 +10482.68 +10821.99 +10813.32 +10934.34 +10906.89 +10941.53 +10894.32 +10940.84 +10943.11 +11177.16 +11083.52 +10952.6 +11116.87 +11148.11 +11208.14 +11078.64 +11081.1 +11161.41 +11426.74 +11483.32 +11363.04 +11409.91 +11464.18 +11451.31 +11566.08 +11563.86 +11362.45 +11350.49 +11405.37 +11424.57 +11447.76 +11549.22 +11523.06 +11523.39 +11590.57 +11686.56 +11670 +11666.96 +11714.64 +11711.63 +11423.48 +11199.65 +11074.69 +11133.94 +11024.15 +10896.45 +10765.74 +10853.54 +11090.87 +11120.95 +11034.03 +11180.56 +10976.51 +10956.55 +11048.38 +10744.16 +10680.16 +10588.86 +10479.72 +10535.39 +10548.2 +10406.04 +10367.51 +10291.12 +10450.65 +10454.51 +10491.84 +10637.42 +10743.94 +10722.48 +10739.95 +10798.28 +10859.7 +10647.46 +10470.63 +10339.43 +10148.67 +10237.34 +9878.72 +9866.23 +9901.33 +10026.6 +9949.93 +9832.9 +9915.92 +10048.96 +10090.35 +9912.17 +9956.74 +9833.12 +9688.68 +9731.87 +9737.82 +9811.28 +9840.16 +9864.36 +9827.55 +9885.47 +9917.99 +10120.54 +10015.45 +10217.36 +10205.48 +10201.47 +10317.24 +10329.65 +10084.15 +10117.78 +10207.27 +10044.21 +9993.87 +9925.09 +10139.96 +10161.28 +10325.76 +10343.58 +10438.23 +10413.34 +10404.42 +10457.13 +10189.18 +10131.6 +10033.41 +10057.04 +9743.23 +9809.57 +9823.97 +9670.52 +9797.07 +9757.2 +9786.37 +9642.93 +9586.52 +9580.38 +9401.32 +9499.17 +9619.66 +9678.38 +9633.55 +9758.75 +9626.79 +9597.24 +9717.92 +9723.05 +9777.93 +9720.4 +9618.85 +9592.86 +9652.99 +9656.93 +9523.2 +9477.75 +9405.39 +9415.63 +9404.22 +9367.41 +9442.93 +9483.93 +9588.2 +9588.37 +9670.98 +9570.14 +9579.05 +9730.25 +9733.22 +9628.67 +9677.86 +9637.93 +9432.63 +9488.19 +9446.81 +9475.47 +9683.39 +9740.81 +9837 +10118.21 +10213.28 +10242.22 +10201.18 +10196.02 +10222.71 +10242.84 +10259.75 +10366.35 +10352.96 +10308.15 +10363.58 +10193.72 +10182.28 +10270.72 +10311.09 +10315.32 +10321.23 +10627.83 +10696.2 +10725.32 +10645.69 +10683.84 +10670.66 +10840.36 +10678.5 +10575.87 +10623.79 +10574.43 +10611.58 +10678.99 +10678.91 +10744.57 +10738.61 +10628.72 +10647.22 +10692.18 +10681.68 +10900.49 +10899.26 +10940.25 +10798.44 +10743.53 +10517.09 +10594.36 +10575.89 +10558.32 +10389.15 +10480.8 +10510.08 +10500.77 +10407.88 +10446.83 +10489.03 +10531.77 +10649.08 +10557.65 +10425.92 +10309.81 +10392.13 +10370.45 +10320.69 +10350.66 +10428.83 +10416.56 +10384.52 +10522.26 +10632.81 +10600.36 +10715.48 +10662.01 +10626.55 +10766.27 +10779.06 +10712.27 +10737.63 +10852.77 +10942.8 +10904.24 +11035.56 +10924.01 +10964.68 +10911.55 +11029.42 +11141.86 +11038.72 +11100.17 +11000.17 +10982.89 +11096.05 +11081.52 +11100.3 +10890.96 +10916.43 +10903.09 +11008.12 +10966.65 +10796.32 +10836.1 +10852.02 +10875.33 +10920.94 +10901.85 +11055.84 +11015.57 +11099.19 +11017.6 +11077.99 +11209.47 +11301.59 +11305.12 +11359.01 +11318.66 +11330.5 +11297.21 +11335.16 +11313.99 +11306.96 +11267.59 diff --git a/data/cdr.dat b/data/cdr.dat new file mode 100644 index 0000000..c7aafef --- /dev/null +++ b/data/cdr.dat @@ -0,0 +1,1000 @@ +16.51 +14.78 +13.80 +12.77 +14.76 +14.14 +14.05 +14.29 +14.78 +14.88 +14.97 +15.15 +15.20 +15.18 +15.10 +15.38 +15.67 +15.77 +15.54 +15.01 +14.98 +15.04 +14.70 +14.56 +14.39 +14.19 +14.04 +14.41 +14.83 +14.80 +14.49 +14.69 +14.69 +14.78 +14.77 +14.49 +14.18 +14.14 +13.80 +14.07 +13.75 +13.70 +13.98 +14.05 +14.05 +13.81 +14.16 +14.02 +14.00 +14.64 +14.45 +14.68 +14.59 +14.59 +14.68 +14.98 +15.18 +15.16 +15.10 +15.92 +16.26 +16.51 +16.34 +16.04 +16.26 +15.87 +16.02 +16.07 +16.46 +16.49 +16.12 +15.65 +15.22 +15.08 +14.78 +15.02 +14.85 +14.98 +14.78 +14.85 +14.78 +15.08 +15.01 +14.86 +14.74 +14.51 +14.64 +14.63 +14.69 +15.03 +15.11 +15.20 +15.38 +15.28 +15.41 +15.28 +15.28 +15.19 +15.08 +14.84 +15.03 +15.18 +14.86 +14.26 +14.29 +14.69 +14.56 +14.78 +15.08 +15.03 +15.46 +15.62 +15.97 +15.82 +15.57 +15.47 +15.77 +15.01 +15.28 +15.23 +15.33 +15.62 +15.66 +15.75 +15.77 +16.36 +16.51 +16.66 +16.37 +16.46 +16.65 +16.76 +16.50 +16.52 +16.49 +16.37 +16.35 +16.37 +16.35 +16.35 +16.35 +16.35 +16.39 +16.46 +16.71 +16.73 +16.50 +16.62 +16.16 +15.92 +15.47 +15.24 +15.34 +15.92 +16.03 +16.22 +16.18 +16.26 +16.41 +16.46 +16.44 +16.43 +16.41 +16.46 +16.40 +16.60 +16.49 +16.71 +16.33 +16.21 +16.15 +16.05 +16.20 +16.24 +16.66 +17.48 +17.45 +17.69 +17.73 +17.72 +17.59 +17.25 +17.28 +17.17 +17.72 +17.61 +17.14 +17.15 +17.05 +16.34 +16.56 +15.92 +15.77 +15.99 +15.99 +15.97 +16.30 +15.96 +15.92 +16.14 +16.13 +16.46 +16.56 +16.38 +16.60 +16.58 +16.61 +16.68 +16.57 +16.45 +15.97 +15.77 +15.76 +15.62 +15.81 +16.07 +16.07 +16.04 +15.99 +15.77 +15.82 +15.97 +15.77 +15.82 +15.82 +15.77 +16.17 +15.93 +15.97 +16.07 +15.82 +16.05 +16.26 +16.34 +16.32 +16.32 +16.18 +16.36 +16.51 +16.85 +17.05 +17.40 +17.80 +17.92 +17.79 +18.09 +18.53 +18.36 +18.61 +18.23 +18.28 +18.24 +18.60 +18.41 +18.28 +18.26 +18.06 +18.96 +19.32 +18.97 +18.92 +18.91 +19.42 +19.40 +20.10 +20.60 +20.99 +20.97 +20.80 +20.30 +20.85 +20.91 +20.86 +21.03 +20.93 +20.89 +20.69 +20.79 +20.16 +19.71 +19.48 +20.35 +20.19 +20.39 +20.70 +20.45 +20.35 +20.16 +20.44 +21.69 +22.91 +24.53 +24.14 +24.35 +24.64 +23.06 +23.29 +23.64 +23.43 +23.06 +23.16 +23.23 +23.43 +23.89 +23.32 +22.52 +21.89 +20.92 +20.03 +24.13 +23.10 +22.34 +22.24 +22.99 +23.65 +23.36 +23.75 +23.36 +23.54 +23.56 +23.51 +24.15 +24.05 +23.16 +23.44 +23.96 +24.15 +24.15 +23.95 +23.39 +23.68 +24.20 +25.13 +25.63 +25.43 +25.74 +26.31 +26.30 +26.12 +25.38 +25.56 +25.92 +25.87 +25.77 +25.60 +25.57 +25.64 +26.12 +26.31 +26.91 +27.05 +26.47 +26.71 +27.05 +27.15 +27.15 +27.34 +27.29 +26.77 +26.47 +26.91 +26.66 +26.60 +24.44 +26.12 +25.63 +24.84 +23.02 +23.95 +23.93 +24.30 +25.18 +25.31 +24.47 +25.08 +24.57 +24.25 +24.38 +24.61 +24.52 +25.21 +25.76 +25.49 +25.85 +25.92 +25.88 +26.02 +26.42 +25.89 +25.97 +26.54 +25.91 +26.22 +26.12 +26.89 +25.53 +26.18 +26.42 +26.71 +26.53 +26.36 +26.61 +26.65 +26.28 +26.31 +26.42 +26.42 +26.17 +26.60 +26.50 +26.57 +26.27 +26.22 +26.51 +26.59 +26.55 +26.27 +26.17 +26.18 +25.91 +23.97 +22.16 +22.67 +23.36 +22.67 +22.38 +22.18 +21.39 +21.02 +22.44 +22.46 +22.92 +22.27 +22.57 +22.67 +22.13 +22.48 +22.47 +22.42 +22.18 +22.23 +22.08 +21.98 +22.44 +22.28 +22.42 +22.28 +23.49 +22.99 +22.82 +22.48 +22.42 +21.83 +21.65 +22.14 +20.99 +20.35 +20.30 +21.70 +21.44 +22.18 +21.34 +21.09 +21.14 +20.65 +20.61 +20.94 +22.22 +22.71 +22.71 +22.87 +22.76 +22.76 +22.52 +22.32 +22.18 +22.19 +21.87 +21.68 +21.89 +21.29 +21.20 +21.30 +20.91 +21.50 +21.82 +21.98 +22.81 +22.79 +22.47 +22.08 +22.67 +22.67 +22.67 +22.82 +23.66 +24.40 +24.18 +23.69 +23.66 +24.54 +24.49 +23.84 +23.85 +24.08 +24.49 +24.62 +24.58 +24.53 +24.35 +24.62 +25.13 +25.63 +25.33 +24.99 +25.81 +25.48 +25.32 +25.49 +25.63 +25.52 +24.93 +25.23 +25.50 +25.48 +25.58 +25.63 +25.62 +25.42 +25.57 +25.52 +25.08 +25.00 +25.30 +25.08 +24.94 +24.80 +24.24 +24.00 +24.15 +24.64 +25.23 +25.23 +25.32 +26.32 +26.00 +26.65 +26.34 +26.15 +26.58 +26.30 +26.71 +27.35 +26.21 +26.45 +25.92 +26.28 +26.17 +26.81 +27.39 +27.01 +27.29 +26.91 +26.41 +25.53 +26.47 +26.02 +26.32 +26.13 +26.41 +26.55 +27.10 +26.53 +25.92 +26.52 +26.81 +27.01 +27.06 +26.99 +27.01 +27.21 +28.09 +28.00 +28.29 +29.08 +28.58 +28.76 +30.55 +31.24 +31.35 +32.13 +32.53 +32.55 +32.75 +32.67 +32.76 +33.22 +34.30 +33.71 +33.51 +33.07 +31.99 +32.08 +33.02 +33.57 +33.85 +34.23 +34.91 +34.75 +34.84 +35.41 +35.80 +37.31 +37.20 +36.47 +38.15 +40.31 +41.66 +41.00 +41.89 +40.71 +42.18 +42.88 +43.46 +42.58 +41.25 +41.89 +39.67 +41.75 +41.33 +40.02 +40.90 +41.00 +41.40 +40.81 +39.98 +38.64 +38.36 +38.70 +38.53 +39.17 +39.29 +40.12 +39.08 +39.03 +38.12 +38.44 +38.93 +38.93 +39.08 +38.35 +39.04 +39.03 +39.18 +38.94 +39.20 +39.39 +39.03 +39.03 +38.44 +39.42 +38.98 +39.31 +39.13 +39.18 +38.98 +39.02 +39.03 +39.00 +38.98 +38.98 +39.41 +39.15 +39.05 +39.43 +39.56 +42.60 +42.60 +47.97 +48.29 +47.90 +47.56 +47.02 +49.53 +50.92 +52.91 +51.85 +50.37 +51.52 +50.77 +51.06 +51.56 +51.75 +52.22 +50.92 +49.77 +50.47 +51.25 +50.83 +51.56 +51.25 +51.89 +51.57 +51.45 +51.63 +51.40 +51.16 +51.45 +51.93 +52.24 +53.67 +54.06 +53.14 +54.20 +54.37 +54.28 +55.42 +57.60 +58.30 +58.64 +58.77 +58.65 +58.40 +58.15 +57.81 +58.15 +58.15 +57.93 +58.84 +60.91 +62.59 +63.76 +65.70 +68.44 +68.30 +68.50 +68.50 +68.21 +68.90 +73.16 +71.56 +73.27 +69.98 +71.16 +69.44 +73.03 +72.62 +71.95 +70.08 +72.22 +72.13 +71.46 +72.13 +71.95 +73.03 +72.92 +74.91 +75.89 +75.39 +75.18 +72.84 +74.67 +74.61 +73.03 +72.15 +71.57 +73.43 +73.13 +72.72 +72.63 +72.25 +71.21 +70.96 +67.92 +65.45 +65.30 +63.87 +65.54 +69.04 +67.62 +65.75 +65.79 +64.85 +64.16 +66.47 +66.82 +68.01 +66.66 +66.44 +65.54 +65.05 +67.75 +67.03 +66.33 +66.14 +65.38 +64.66 +64.56 +65.24 +67.91 +68.01 +70.46 +72.54 +71.95 +74.50 +77.60 +78.93 +82.00 +82.00 +80.00 +80.00 +80.20 +81.69 +82.22 +81.70 +83.99 +81.74 +82.60 +83.99 +83.37 +82.96 +82.50 +83.62 +86.00 +86.00 +85.50 +86.00 +86.04 +85.31 +83.63 +82.70 +81.50 +79.70 +81.40 +81.03 +82.79 +83.40 +81.85 +81.91 +82.50 +83.20 +86.49 +87.00 +87.00 +87.20 +87.28 +87.39 +86.78 +86.50 +87.20 +86.69 +85.65 +85.32 +85.70 +84.81 +84.20 +84.84 +84.00 +84.61 +87.00 +86.80 +86.50 +86.50 +85.06 +84.71 +84.80 +84.90 +84.40 +80.52 +81.01 +83.40 +84.20 +85.55 +83.80 +82.01 +90.01 +94.65 +100.00 +104.60 +107.00 +106.60 +103.90 +106.00 +109.50 +113.90 +112.00 +114.00 +113.15 +111.05 +112.15 +114.80 +116.25 +114.55 +115.00 +113.55 +113.90 +115.70 +115.95 +115.85 +119.00 +117.00 +117.80 +117.95 +114.50 +111.50 +111.75 +112.50 +113.30 +113.40 +113.80 +117.80 +118.50 +117.95 +120.60 +120.00 +119.20 +121.00 +124.50 +126.25 +125.20 +124.90 +114.75 +107.40 +107.00 +110.00 +111.30 +113.50 +112.45 +106.00 +104.80 +105.00 +107.10 +104.50 +98.00 +101.50 +96.80 +96.35 +99.56 +97.99 +95.92 +94.00 +89.50 +91.67 +97.09 +95.35 +96.50 +95.95 +99.90 +99.55 +100.35 +100.15 +102.00 +99.00 +97.00 +98.00 +98.00 +99.00 +100.70 +100.00 +98.15 +104.20 +107.00 +105.80 +111.10 +119.00 +119.70 +121.30 +119.30 +118.30 +116.50 +112.00 +114.80 +115.80 +114.00 +116.00 +115.00 +113.40 +109.50 +106.00 +111.30 +111.00 +106.20 +106.70 +109.10 +108.90 +108.90 +110.80 +109.00 +109.00 +109.50 +109.70 +108.60 +106.90 +107.60 +107.00 +104.80 +105.90 +106.00 +103.60 +109.80 diff --git a/data/dogecoin.dat b/data/dogecoin.dat new file mode 100644 index 0000000..24d1cb3 --- /dev/null +++ b/data/dogecoin.dat @@ -0,0 +1,365 @@ +0.005301 +0.000205 +0.000206 +0.000210 +0.000209 +0.000208 +0.000211 +0.000204 +0.000211 +0.000229 +0.000247 +0.000238 +0.000243 +0.000235 +0.000223 +0.000219 +0.000235 +0.000236 +0.000246 +0.000243 +0.000242 +0.000264 +0.000298 +0.000272 +0.000254 +0.000273 +0.000272 +0.000304 +0.000328 +0.000335 +0.000489 +0.000427 +0.000432 +0.000442 +0.000450 +0.000398 +0.000432 +0.000381 +0.000400 +0.000390 +0.000414 +0.000425 +0.000426 +0.000418 +0.000454 +0.000459 +0.000459 +0.000448 +0.000443 +0.000451 +0.000464 +0.000522 +0.000515 +0.000527 +0.000544 +0.000632 +0.000678 +0.000734 +0.000746 +0.000686 +0.000610 +0.000678 +0.000744 +0.000840 +0.001169 +0.001305 +0.001521 +0.001239 +0.001239 +0.001212 +0.001183 +0.001184 +0.001274 +0.001128 +0.001059 +0.001318 +0.001508 +0.001518 +0.001900 +0.003062 +0.003405 +0.003562 +0.003659 +0.002994 +0.002424 +0.002541 +0.002579 +0.002732 +0.002623 +0.002657 +0.002867 +0.003026 +0.003251 +0.003179 +0.003873 +0.003741 +0.003302 +0.003575 +0.003453 +0.003313 +0.003601 +0.003253 +0.003313 +0.003092 +0.003043 +0.003163 +0.003322 +0.003230 +0.003141 +0.003218 +0.003125 +0.003104 +0.003143 +0.003135 +0.002961 +0.002750 +0.002623 +0.002793 +0.002656 +0.002602 +0.002645 +0.002481 +0.002533 +0.002518 +0.002714 +0.002636 +0.002397 +0.002440 +0.002330 +0.001952 +0.001779 +0.001938 +0.001823 +0.001681 +0.001484 +0.001307 +0.001520 +0.001864 +0.001689 +0.001935 +0.001936 +0.002095 +0.001972 +0.001980 +0.001773 +0.001810 +0.001856 +0.001782 +0.001768 +0.001719 +0.001718 +0.001792 +0.001788 +0.001795 +0.001820 +0.002087 +0.001909 +0.001949 +0.001961 +0.001937 +0.001896 +0.001880 +0.001856 +0.001807 +0.001762 +0.001738 +0.001774 +0.001710 +0.001678 +0.001678 +0.001707 +0.001712 +0.001716 +0.001732 +0.001816 +0.001790 +0.001778 +0.001760 +0.001825 +0.001867 +0.002105 +0.002064 +0.002543 +0.002226 +0.002153 +0.001786 +0.001908 +0.002019 +0.001928 +0.001596 +0.001568 +0.001395 +0.001463 +0.001440 +0.001398 +0.000854 +0.000865 +0.000867 +0.000853 +0.000947 +0.000890 +0.000862 +0.000755 +0.000772 +0.000954 +0.000892 +0.001141 +0.001151 +0.001173 +0.001080 +0.001082 +0.001145 +0.001084 +0.001085 +0.001108 +0.001024 +0.001001 +0.001056 +0.001066 +0.001056 +0.000991 +0.001036 +0.001046 +0.001062 +0.001066 +0.001110 +0.001106 +0.001164 +0.001067 +0.001047 +0.001064 +0.001050 +0.001007 +0.001023 +0.001016 +0.001092 +0.001056 +0.001051 +0.001052 +0.001037 +0.001173 +0.001151 +0.001124 +0.001138 +0.001151 +0.001121 +0.001189 +0.001182 +0.001154 +0.001177 +0.001222 +0.001415 +0.001163 +0.001201 +0.001038 +0.001211 +0.001184 +0.001339 +0.001390 +0.001313 +0.001373 +0.001376 +0.001394 +0.001389 +0.001823 +0.001891 +0.001908 +0.002072 +0.002026 +0.001988 +0.002363 +0.002080 +0.002079 +0.002148 +0.002149 +0.002223 +0.002463 +0.002479 +0.002663 +0.002720 +0.002779 +0.002617 +0.002547 +0.002798 +0.003304 +0.003461 +0.003709 +0.003762 +0.005933 +0.005984 +0.006433 +0.005666 +0.006661 +0.007425 +0.006054 +0.007259 +0.008582 +0.008931 +0.009411 +0.008872 +0.008486 +0.009391 +0.007860 +0.008972 +0.008909 +0.009145 +0.009320 +0.009644 +0.012167 +0.014863 +0.017088 +0.015045 +0.013420 +0.013102 +0.011469 +0.013056 +0.013023 +0.011685 +0.009857 +0.006822 +0.007648 +0.007969 +0.007871 +0.008448 +0.007131 +0.006734 +0.006673 +0.007083 +0.007667 +0.007237 +0.007373 +0.007465 +0.006967 +0.006024 +0.006010 +0.005029 +0.004475 +0.005164 +0.004399 +0.003533 +0.004361 +0.004297 +0.004566 +0.005000 +0.004989 +0.004956 +0.005472 +0.005638 +0.006730 +0.007347 +0.007034 +0.007049 +0.006424 +0.006697 +0.007094 +0.006581 +0.006259 +0.006648 +0.006324 +0.006142 +0.006339 +0.006291 +0.006018 +0.006215 +0.005482 diff --git a/data/ltc.dat b/data/ltc.dat new file mode 100644 index 0000000..d6ddbff --- /dev/null +++ b/data/ltc.dat @@ -0,0 +1,962 @@ +1.7906 +1.8019 +1.75 +1.7791 +1.8003 +1.8498 +2.002 +2.01 +2.8601 +2.8358 +3.1018 +2.74 +3.0333 +3 +2.9975 +2.959 +2.7733 +2.838 +2.876 +3.125 +3.1194 +3.7707 +4.092 +3.9431 +4.056 +4.151 +4.143 +4.938 +5.38 +5.201 +6.464 +7.567 +4.4454 +4.328 +5.3081 +4.7 +4.601 +4.122 +3.71 +3.7501 +4.01 +3.707 +3.9719 +3.777 +3.8696 +3.7869 +4.6063 +4.6779 +4.7 +4.69 +5.087 +4.807 +4.6071 +4.6402 +4.1488 +4.187 +4.195 +4.41 +4.37 +4.0524 +4.2484 +3.871 +3.94 +3.9732 +4.161 +4.0249 +3.9 +4.054 +3.9412 +3.98 +4.01 +3.363 +3.4982 +3.6036 +3.5697 +3.5383 +3.3824 +3.051 +2.96 +2.9488 +2.89 +2.9 +2.893 +2.8565 +2.848 +2.84 +2.8058 +2.6482 +2.7098 +2.951 +3.0789 +3.0597 +3.05 +2.9424 +2.955 +2.965 +2.8351 +2.816 +2.8498 +2.8198 +2.8148 +2.9337 +2.9653 +2.884 +2.851 +2.8096 +2.8536 +2.86 +2.9202 +2.902 +2.8988 +2.8748 +3.08 +2.9839 +2.99 +3.0135 +2.9929 +3.031 +3.0082 +3.0419 +3.169 +3.0688 +3.062 +3.115 +3.1141 +3.1583 +3.1675 +3.197 +3.1649 +3.0907 +3.101 +3.071 +3.0261 +3.0402 +3.0797 +3.0787 +3.145 +3.1318 +3.144 +3.1011 +3.1186 +3.1055 +3.0988 +3.7993 +3.95 +3.6891 +3.89 +4.1342 +4.55 +4 +3.85 +3.523 +3.532 +3.3792 +3.4223 +3.0999 +2.9854 +3.3 +3.2177 +3.2299 +3.074 +3.1974 +3.226 +3.182 +3.14 +3.131 +3.156 +3.1262 +3.154 +3.1018 +3.376 +3.6444 +3.605 +3.546 +3.7 +3.6255 +3.4312 +3.33 +3.3798 +3.335 +3.528 +3.4399 +3.634 +3.8273 +3.6906 +3.653 +3.89 +3.6 +3.58 +3.5879 +3.7875 +3.6807 +3.695 +3.7201 +3.6997 +3.5 +3.406 +3.4085 +3.5601 +3.6418 +3.6011 +3.445 +3.4678 +3.464 +3.489 +3.452 +3.4401 +3.5189 +3.499 +3.4869 +3.507 +3.489 +3.45 +3.62 +3.5919 +3.58 +3.535 +3.5517 +3.4599 +3.4719 +3.4334 +2.95 +3.1 +3.001 +3.055 +3.0099 +3.37 +3.2057 +3.0411 +3.1075 +3.1847 +3.0947 +3.4239 +3.4742 +3.4728 +3.384 +3.3567 +3.3635 +3.4334 +3.4112 +3.4197 +3.4489 +3.435 +3.346 +3.304 +3.2254 +3.1726 +3.1778 +3.241 +3.2179 +3.2541 +3.264 +3.365 +3.2569 +3.2803 +3.3039 +3.3114 +3.313 +3.2924 +3.1457 +3.1582 +3.1694 +3.192 +3.2132 +3.226 +3.2187 +3.2075 +3.2372 +3.296 +3.27 +3.228 +3.2096 +3.254 +3.2416 +3.2582 +3.2443 +3.245 +3.2687 +3.2467 +3.2305 +3.2324 +3.2302 +3.233 +3.234 +3.2625 +3.2693 +3.26 +3.2952 +3.3104 +3.2849 +3.2511 +3.3199 +3.3 +3.375 +3.356 +3.3698 +3.6711 +3.83 +4.0837 +3.8931 +3.8298 +3.8207 +3.67 +3.6969 +3.6743 +3.734 +3.7333 +3.7203 +3.8452 +3.98 +3.966 +4.08 +3.8398 +3.8807 +3.859 +3.9351 +4.0181 +4.0707 +4.007 +3.9669 +4.0212 +3.7989 +3.87 +3.9353 +3.8383 +3.958 +3.95 +4.0456 +4.1025 +4.4453 +4.487 +4.7503 +4.59 +4.76 +4.7162 +4.8967 +4.82 +4.8632 +4.979 +4.7738 +4.821 +4.767 +4.8969 +5.0993 +5.25 +5.2789 +5.136 +5.2588 +5.695 +5.6492 +5.578 +5.6031 +5.381 +4.8546 +4.0007 +3.888 +4.2775 +4.243 +4.0731 +4.175 +4.1299 +4.0599 +4.2091 +4.2663 +4.6532 +4.2809 +4.5046 +4.4219 +4.4799 +4.102 +4.25 +4.1036 +4.138 +4.1274 +4.1843 +4.1734 +4.1701 +4.19 +4.16 +4.1928 +4.1521 +4.19 +4.1574 +4.114 +4.036 +4.0596 +4.0933 +4.0102 +3.98 +3.9536 +3.993 +4.0767 +4.0551 +3.942 +3.8534 +3.7332 +3.56 +3.746 +3.66 +3.69 +3.63 +3.53 +3.6 +3.5702 +3.5907 +3.6226 +3.6239 +3.6257 +3.672 +3.95 +3.8414 +3.8159 +3.84 +3.7586 +3.7645 +3.776 +3.803 +3.8107 +3.8262 +3.8048 +3.9154 +4.0101 +3.9781 +3.97 +4.0051 +4.0289 +3.9789 +4.0199 +3.8977 +3.8569 +3.845 +3.9017 +3.86 +3.83 +3.811 +3.8334 +3.837 +3.7948 +3.8011 +3.7506 +3.808 +3.8234 +3.8 +3.8582 +3.836 +3.857 +3.8529 +3.8486 +3.85 +3.8491 +3.8165 +3.8142 +3.83 +3.8478 +3.8649 +3.8295 +3.7866 +3.784 +3.8304 +3.81 +3.9329 +3.9228 +3.892 +3.881 +3.8365 +3.8272 +3.8157 +3.789 +3.8569 +3.918 +3.8997 +3.881 +3.916 +3.9885 +3.992 +3.9947 +4.0898 +4.03 +4 +4.11 +4.1449 +3.8601 +3.8979 +3.9138 +3.9184 +3.887 +3.8635 +3.853 +3.8192 +3.8057 +3.7754 +3.883 +3.8997 +3.9031 +3.94 +3.8979 +3.909 +3.9569 +3.89 +3.9476 +3.8991 +3.8609 +3.8997 +3.8908 +3.8231 +3.873 +3.8252 +3.8809 +3.8777 +3.9 +3.91 +3.9056 +3.4783 +3.52 +3.6601 +3.68 +3.6987 +3.6823 +3.633 +3.6386 +3.653 +3.6021 +3.65 +3.6 +3.7195 +3.672 +3.6493 +3.656 +3.632 +3.6742 +4.6161 +4.431 +4.2991 +4.257 +4.3633 +4.5976 +4.59 +4.4135 +4.3635 +4.4997 +4.58 +4.593 +4.59 +4.2127 +3.84 +3.963 +4.02 +4.34 +4.574 +3.9443 +4.0001 +3.9262 +3.9466 +3.9135 +3.8927 +3.95 +3.8949 +3.907 +3.9098 +3.9208 +3.85 +3.8246 +3.733 +3.711 +3.7425 +4.0382 +4.0649 +4.0352 +4.0283 +3.9701 +3.9403 +3.958 +3.9208 +3.737 +3.8296 +3.8153 +3.7394 +3.7698 +3.83 +3.8933 +3.8831 +3.8961 +3.8139 +3.8 +3.8086 +3.8566 +3.9009 +3.9057 +3.9488 +3.8801 +3.8747 +3.8728 +3.8061 +3.851 +4.0601 +4.1105 +4 +4.0137 +4.1003 +4.0063 +3.8669 +3.8734 +3.8109 +3.806 +3.8701 +4.3739 +4.1707 +4.3061 +4.2982 +4.1 +4.0049 +3.9371 +4.0584 +4.0173 +3.9546 +4.0076 +4.1403 +4.0817 +4.0862 +4.1263 +4.1837 +4.306 +7.78 +7.13 +7.5874 +8.333 +8.6 +9.095 +12.4 +10.854 +10.014 +10.732 +9.35 +9.9251 +9.7771 +11.79 +11.234 +11.915 +11.848 +12.05 +11.66 +11.521 +10.608 +11.592 +12.851 +15.411 +16.689 +16.2 +16.642 +16.242 +16.022 +15.498 +16.988 +16.84 +17.298 +17.2 +23.001 +24.941 +26.213 +28.674 +30.696 +28.706 +34 +32.335 +31 +27.801 +29.399 +29.395 +25.791 +23.72 +26.011 +29.134 +27.373 +27.202 +25.61 +23.931 +30.692 +33.579 +27.211 +24.21 +22.095 +22.817 +24.789 +23.667 +24.777 +26.5 +26.967 +26.413 +27.415 +29.999 +29.762 +28.1 +29.847 +29.506 +28.72 +33.95 +28 +30.08 +28.266 +28.565 +33.248 +45.358 +43.112 +47.197 +45.77 +43.76 +45.85 +45.23 +41.311 +40.158 +37.78 +39.547 +41.192 +39.269 +38.83 +37.01 +40.4 +45.298 +54.59 +52.75 +50.831 +45.686 +50.924 +48.2 +44.315 +43.435 +46.84 +45.165 +42.35 +38.379 +40.935 +42.129 +43.469 +40 +44.85 +45.45 +47.01 +45.107 +45.1 +42.081 +42.101 +41.8 +40.439 +41.052 +40.001 +42.107 +43.12 +41.812 +42.579 +43.018 +46.255 +45.486 +46 +49 +47.56 +46.5 +46.964 +45.879 +45.276 +45.497 +42.967 +43.911 +43.618 +46.52 +44.976 +45.685 +47.971 +46.25 +53.004 +49.663 +50.916 +51.529 +60.5 +62.14 +63.534 +65.448 +72.691 +87.137 +78.494 +78.527 +66.8 +73.28 +81.111 +80.1 +72.91 +70.75 +67.205 +68.121 +65.945 +61.652 +45.001 +51.821 +51.824 +50.718 +56.289 +52.58 +51.502 +46.399 +47.5 +49.28 +47.3 +52.397 +52.203 +56.83 +54.919 +52.876 +55.56 +54.872 +53.261 +52.083 +51.235 +51.665 +52.056 +52.571 +53.31 +50.068 +50.698 +50.804 +60.503 +59.306 +63.939 +65.86 +64.782 +59.172 +60.499 +59.55 +59.996 +58.014 +56.422 +54.533 +55.635 +56.039 +55.5 +54.958 +54.01 +56.838 +56.18 +55.552 +52.849 +53.989 +55.83 +54.636 +54.441 +54.375 +60.34 +62.409 +64.31 +58.626 +61.686 +58.261 +61 +61.99 +63.03 +70.654 +67.132 +69.591 +71.72 +72.331 +69.99 +71.735 +72.37 +77.886 +88.443 +85.456 +90.761 +94.003 +83.675 +85.768 +97.841 +98.83 +99.865 +103.42 +99.487 +96.503 +93.56 +120.9 +149 +144.6 +210.11 +292.12 +295.35 +276.31 +295.55 +295.67 +313.5 +355.5 +340.8 +304.31 +306.99 +248.38 +269 +261.99 +261.14 +278.78 +263.53 +247.45 +239.51 +206.99 +225.4 +223.51 +250.11 +244.21 +237.76 +242.9 +278 +271.05 +252.77 +245 +249.24 +225.52 +234.96 +257.7 +235.24 +231.05 +181.8 +186.71 +187.66 +191.68 +209.85 +189.96 +179.54 +177.64 +180.36 +178.8 +175.37 +181.49 +196.08 +181.51 +167.35 +164.5 +143.2 +132 +161.35 +147.47 +125.32 +141.81 +137.93 +149.86 +163.61 +154.82 +148.92 +161.39 +159.19 +211.97 +220.47 +228.5 +228.9 +213.57 +221.63 +228.98 +210.05 +192.47 +206.21 +206.33 +218.13 +218.36 +214.96 +202.02 +209.26 +213.32 +209.92 +208.32 diff --git a/data/msft.dat b/data/msft.dat new file mode 100644 index 0000000..0bd2ddb --- /dev/null +++ b/data/msft.dat @@ -0,0 +1,1260 @@ +28.15 +28.35 +28.09 +28.139999 +28 +27.870001 +27.91 +27.92 +28.139999 +28.040001 +28.1 +28.18 +28.32 +28.110001 +28.25 +28.16 +28.16 +28.370001 +28.610001 +28.610001 +28.799999 +28.559999 +28.6 +28.700001 +28.59 +29.610001 +30.280001 +28.940001 +28.790001 +28.690001 +28.969999 +28.83 +28.790001 +29.77 +30.83 +30.6 +31.76 +31.940001 +31.790001 +32.610001 +33.099998 +32.720001 +33.16 +33.490002 +33.75 +33.310001 +32.990002 +32.66 +32.689999 +33.029999 +33.529999 +33.849998 +34.080002 +34.869999 +35.080002 +34.849998 +34.610001 +34.150002 +34.27 +35.02 +34.880001 +35.029999 +34.900002 +35.59 +34.990002 +34.779999 +34.959999 +35.669998 +35.470001 +34.84 +35 +34.720001 +34.400002 +35 +34.98 +34.59 +33.490002 +33.27 +33.720001 +33.669998 +34.349998 +34.619999 +34.540001 +34.360001 +33.939999 +34.009998 +34.209999 +34.330002 +34.349998 +34.700001 +35.689999 +35.669998 +36.169998 +36.27 +35.740002 +35.439999 +31.4 +32.009998 +31.82 +31.959999 +31.389999 +31.620001 +31.540001 +31.85 +31.84 +31.67 +31.889999 +31.700001 +31.58 +32.060001 +32.889999 +32.700001 +32.869999 +32.23 +32.349998 +31.790001 +31.799999 +31.389999 +31.620001 +31.610001 +32.389999 +34.75 +34.150002 +33.259998 +33.02 +33.549999 +33.400002 +31.879999 +31.200001 +31.23 +31.15 +31.66 +32.389999 +32.740002 +32.689999 +33.029999 +32.799999 +32.93 +33.32 +33.639999 +32.790001 +32.740002 +32.450001 +32.509998 +32.77 +33.27 +33.279999 +33.580002 +33.919998 +33.860001 +33.880001 +33.299999 +33.009998 +33.07 +33.759998 +34.130001 +34.450001 +34.490002 +34.639999 +34.919998 +34.959999 +34.990002 +34.580002 +33.759998 +33.720001 +35.73 +35.57 +35.52 +35.540001 +35.41 +35.529999 +35.939999 +36.639999 +38.18 +37.5 +37.779999 +37.59 +37.360001 +38.16 +38.02 +37.84 +37.200001 +36.740002 +37.080002 +37.400002 +37.57 +37.639999 +37.349998 +37.599998 +38.130001 +38.450001 +38.310001 +38.939999 +38 +38.360001 +38.709999 +38.110001 +37.610001 +37.220001 +36.689999 +36.889999 +36.52 +36.580002 +36.25 +36.799999 +36.619999 +37.080002 +37.439999 +37.290001 +37.290001 +37.41 +37.16 +36.91 +36.130001 +36.41 +35.759998 +35.529999 +36.040001 +34.98 +35.779999 +36.759998 +36.889999 +36.380001 +36.169998 +35.93 +36.060001 +36.810001 +36.029999 +36.27 +36.66 +36.860001 +37.84 +36.48 +36.349998 +35.82 +36.18 +36.560001 +36.799999 +37.169998 +37.470001 +37.610001 +37.619999 +37.419998 +37.509998 +37.75 +37.98 +37.689999 +37.540001 +37.470001 +37.860001 +38.310001 +37.779999 +38.41 +38.110001 +38.150002 +37.900002 +37.82 +38.02 +38.27 +37.889999 +37.700001 +38.049999 +39.549999 +39.27 +40.330002 +40.16 +40.5 +40.34 +39.790001 +39.360001 +40.299999 +40.990002 +41.419998 +41.349998 +41.009998 +39.869999 +39.799999 +39.82 +40.470001 +39.360001 +39.209999 +39.18 +39.75 +40.400002 +40.009998 +39.939999 +39.990002 +39.689999 +39.860001 +39.91 +40.869999 +40.509998 +40.400002 +40 +39.689999 +39.43 +39.060001 +39.419998 +39.639999 +39.540001 +39.970001 +40.419998 +40.240002 +39.599998 +39.830002 +39.75 +39.68 +40.349998 +40.099998 +40.119999 +40.189999 +40.009998 +40.34 +40.939999 +40.790001 +40.290001 +40.32 +41.209999 +41.48 +41.27 +41.110001 +40.860001 +40.580002 +41.23 +41.5 +41.68 +41.650002 +41.509998 +41.68 +41.990002 +41.75 +42.029999 +41.720001 +42.25 +41.700001 +41.869999 +41.900002 +41.799999 +41.990002 +41.779999 +41.669998 +41.689999 +42.09 +42.139999 +42.450001 +44.080002 +44.529999 +44.689999 +44.84 +44.830002 +44.869999 +44.400002 +44.5 +43.970001 +43.889999 +43.580002 +43.16 +42.860001 +43.369999 +43.080002 +42.740002 +43.23 +43.200001 +43.200001 +43.52 +44.080002 +44.27 +44.790001 +45.110001 +45.330002 +44.950001 +45.220001 +45.150002 +45.169998 +45.009998 +44.869999 +44.880001 +45.43 +45.09 +44.959999 +45.259998 +45.91 +46.470001 +46.759998 +46.84 +47 +46.700001 +46.240002 +46.759998 +46.52 +46.68 +47.52 +47.060001 +46.560001 +47.080002 +46.040001 +46.41 +46.439999 +46.360001 +45.900002 +45.759998 +46.09 +46.09 +45.529999 +46.779999 +45.849998 +44.029999 +43.650002 +43.73 +43.220001 +42.740002 +43.630001 +44.080002 +44.880001 +44.380001 +45.02 +46.130001 +45.91 +46.490002 +46.619999 +46.049999 +46.950001 +47.439999 +47.57 +47.860001 +48.700001 +48.68 +48.889999 +48.869999 +48.779999 +49.610001 +49.580002 +49.459999 +48.740002 +48.220001 +48.700001 +47.98 +47.59 +47.470001 +47.75 +47.810001 +48.619999 +48.459999 +48.080002 +48.84 +48.419998 +47.700001 +47.59 +46.900002 +47.169998 +46.950001 +46.669998 +45.16 +45.740002 +47.52 +47.66 +47.98 +48.450001 +48.139999 +47.880001 +47.450001 +47.02 +46.450001 +46.759998 +46.330002 +45.650002 +46.23 +47.59 +47.189999 +46.599998 +46.360001 +45.959999 +45.48 +46.240002 +46.389999 +45.919998 +47.130001 +47.18 +47.009998 +42.66 +41.189999 +42.009998 +40.400002 +41.279999 +41.599998 +41.84 +42.450001 +42.41 +42.360001 +42.599998 +42.380001 +43.09 +43.869999 +43.580002 +43.529999 +43.5 +43.860001 +44.150002 +44.09 +43.990002 +44.060001 +43.849998 +43.880001 +43.279999 +43.060001 +43.110001 +42.360001 +42.849998 +42.029999 +41.98 +41.02 +41.380001 +41.560001 +41.700001 +42.5 +42.290001 +42.880001 +42.860001 +42.900002 +41.459999 +41.209999 +40.970001 +40.959999 +40.66 +40.720001 +40.290001 +41.549999 +41.529999 +41.419998 +41.48 +41.720001 +41.759998 +41.650002 +42.259998 +42.16 +41.619999 +42.91 +42.639999 +42.990002 +43.34 +47.869999 +48.029999 +49.16 +49.060001 +48.639999 +48.66 +48.240002 +47.599998 +46.279999 +46.700001 +47.75 +47.369999 +47.349998 +47.630001 +48.720001 +48.299999 +48.009998 +47.580002 +47.580002 +47.419998 +46.900002 +46.59 +47.610001 +47.450001 +46.860001 +47.23 +46.919998 +46.849998 +46.360001 +46.139999 +45.73 +45.650002 +46.610001 +46.439999 +45.970001 +45.48 +45.830002 +45.970001 +46.720001 +46.099998 +46.23 +45.91 +45.639999 +45.650002 +45.259998 +44.369999 +44.150002 +44.450001 +44.400002 +44.389999 +44.299999 +44.240002 +44.52 +44.610001 +45.540001 +45.619999 +45.759998 +46.66 +46.619999 +46.919998 +47.279999 +45.540001 +46.110001 +45.939999 +45.349998 +45.34 +46.290001 +46.880001 +46.700001 +46.810001 +47.540001 +47.580002 +46.619999 +46.740002 +47.330002 +46.41 +46.740002 +46.73 +47 +47.32 +47.27 +46.610001 +45.66 +43.07 +41.68 +40.470001 +42.709999 +43.900002 +43.93 +43.52 +41.82 +43.360001 +43.5 +42.610001 +43.889999 +43.07 +43.290001 +43.48 +43.040001 +43.98 +44.299999 +44.25 +43.48 +44.110001 +43.900002 +43.869999 +43.91 +43.939999 +43.290001 +43.439999 +44.259998 +44.610001 +45.57 +46.630001 +46.75 +46.799999 +47.450001 +47.110001 +47 +46.889999 +46.68 +47.009998 +47.509998 +47.619999 +47.77 +47.200001 +48.029999 +52.869999 +54.25 +53.689999 +53.98 +53.360001 +52.639999 +53.240002 +54.150002 +54.400002 +54.380001 +54.919998 +54.16 +53.509998 +53.650002 +53.32 +52.84 +53.77 +52.970001 +53.849998 +53.939999 +54.189999 +54.189999 +54.25 +53.689999 +53.93 +54.349998 +55.220001 +55.209999 +54.200001 +55.91 +55.810001 +55.790001 +54.98 +55.27 +54.060001 +55.139999 +55.200001 +56.130001 +55.700001 +54.130001 +54.830002 +55.349998 +55.82 +55.669998 +55.950001 +56.549999 +56.310001 +55.48 +54.799999 +55.049999 +54.049999 +52.169998 +52.330002 +52.299999 +52.779999 +51.639999 +53.110001 +50.990002 +50.560001 +50.790001 +50.48 +52.290001 +51.790001 +52.169998 +51.220001 +52.060001 +55.09 +54.709999 +53 +52.16 +52 +50.16 +49.41 +49.279999 +49.709999 +49.689999 +50.5 +51.09 +52.419998 +52.189999 +51.82 +52.650002 +51.18 +51.360001 +52.099998 +51.299999 +50.880001 +52.580002 +52.950001 +52.349998 +52.029999 +51.029999 +51.650002 +52.84 +52.049999 +53.07 +53.169998 +53.59 +54.349998 +54.66 +53.490002 +53.860001 +54.07 +53.970001 +54.209999 +53.540001 +54.709999 +55.049999 +55.23 +55.57 +55.43 +54.560001 +55.119999 +54.459999 +54.419998 +54.310001 +54.650002 +55.349998 +55.360001 +55.650002 +56.459999 +56.389999 +55.59 +55.779999 +51.779999 +52.110001 +51.439999 +50.939999 +49.900002 +49.869999 +50.610001 +49.779999 +49.869999 +49.939999 +50.389999 +50.07 +51.02 +51.049999 +51.509998 +51.080002 +51.830002 +50.509998 +50.810001 +50.32 +50.619999 +50.029999 +51.59 +52.119999 +51.889999 +52.32 +53 +52.849998 +52.48 +51.790001 +52.130001 +52.099998 +52.040001 +51.619999 +51.48 +50.139999 +49.830002 +49.689999 +50.389999 +50.130001 +50.07 +51.189999 +50.990002 +51.91 +49.830002 +48.43 +49.439999 +50.540001 +51.169998 +51.16 +51.169998 +51.380001 +51.380001 +52.299999 +52.59 +53.209999 +53.509998 +53.740002 +53.700001 +53.959999 +53.09 +55.91 +55.799999 +56.57 +56.73 +56.759998 +56.189999 +56.209999 +56.68 +56.580002 +56.580002 +56.970001 +57.389999 +57.959999 +58.060001 +58.200001 +58.02 +58.299999 +57.939999 +58.119999 +57.439999 +57.560001 +57.599998 +57.619999 +57.669998 +57.889999 +57.950001 +58.169998 +58.029999 +58.099998 +57.889999 +57.459999 +57.59 +57.669998 +57.610001 +57.66 +57.43 +56.209999 +57.049999 +56.529999 +56.259998 +57.189999 +57.25 +56.93 +56.810001 +57.759998 +57.82 +57.43 +56.900002 +57.950001 +58.029999 +57.400002 +57.599998 +57.419998 +57.240002 +57.639999 +57.740002 +57.799999 +58.040001 +57.189999 +57.110001 +56.919998 +57.419998 +57.220001 +57.66 +57.529999 +57.25 +59.66 +61 +60.990002 +60.630001 +60.099998 +59.869999 +59.919998 +59.799999 +59.43 +59.209999 +58.709999 +60.419998 +60.470001 +60.169998 +58.700001 +59.02 +58.119999 +58.869999 +59.650002 +60.639999 +60.349998 +60.860001 +61.119999 +60.400002 +60.529999 +60.610001 +61.09 +60.259998 +59.200001 +59.25 +60.220001 +59.950001 +61.369999 +61.009998 +61.970001 +62.169998 +62.98 +62.68 +62.580002 +62.299999 +63.619999 +63.540001 +63.540001 +63.549999 +63.240002 +63.279999 +62.990002 +62.900002 +62.139999 +62.580002 +62.299999 +62.299999 +62.84 +62.639999 +62.619999 +63.189999 +62.610001 +62.700001 +62.529999 +62.5 +62.299999 +62.740002 +62.959999 +63.52 +63.68 +64.269997 +65.779999 +65.129997 +64.650002 +63.580002 +63.169998 +63.68 +63.639999 +63.43 +63.34 +64.059998 +64 +64.720001 +64.57 +64.529999 +64.519997 +64.620003 +64.489998 +64.360001 +64.620003 +64.620003 +64.230003 +63.98 +64.940002 +64.010002 +64.25 +64.269997 +64.400002 +64.989998 +64.730003 +64.93 +64.709999 +64.410004 +64.75 +64.639999 +64.870003 +64.93 +64.209999 +65.029999 +64.870003 +64.980003 +65.099998 +65.290001 +65.470001 +65.709999 +65.860001 +65.550003 +65.730003 +65.559998 +65.730003 +65.68 +65.529999 +65.480003 +65.230003 +64.949997 +65.480003 +65.389999 +65.040001 +65.5 +66.400002 +67.529999 +67.919998 +67.830002 +68.269997 +68.459999 +69.410004 +69.300003 +69.080002 +68.809998 +69 +68.940002 +69.040001 +69.309998 +68.459999 +68.379997 +68.43 +69.410004 +67.480003 +67.709999 +67.690002 +68.449997 +68.68 +68.769997 +69.620003 +69.959999 +70.410004 +69.839996 +70.099998 +71.760002 +72.279999 +72.519997 +72.389999 +71.949997 +70.32 +69.779999 +70.650002 +70.269997 +69.900002 +70 +70.870003 +69.910004 +70.269997 +70.260002 +71.209999 +70.529999 +69.209999 +69.800003 +68.489998 +68.93 +68.169998 +69.080002 +68.57 +69.459999 +69.980003 +69.989998 +71.150002 +71.769997 +72.779999 +73.349998 +73.300003 +73.860001 +74.220001 +73.790001 +73.599998 +74.190002 +74.050003 +73.160004 +73.040001 +72.699997 +72.580002 +72.260002 +72.150002 +72.68 +72.400002 +72.790001 +72.470001 +71.410004 +72.5 +73.589996 +73.220001 +73.650002 +72.400002 +72.489998 +72.150002 +73.160004 +72.720001 +72.690002 +72.82 +72.830002 +73.050003 +74.010002 +74.769997 +73.940002 +73.610001 +73.400002 +74.339996 +73.980003 +74.760002 +74.68 +75.209999 +74.769997 +75.309998 +75.160004 +75.440002 +74.940002 +74.209999 +74.410004 +73.260002 +73.260002 +73.849998 +73.870003 +74.489998 +74.610001 +74.260002 +74.690002 +75.970001 +76 +76.290001 +76.290001 +76.419998 +77.120003 +77.489998 +77.650002 +77.589996 +77.610001 +77.910004 +78.809998 +78.830002 +78.860001 +78.629997 +78.760002 +83.809998 +83.889999 +83.18 +83.18 +84.050003 +84.139999 +84.470001 +84.269997 +84.559998 +84.089996 +83.870003 +83.93 +84.050003 +82.980003 +83.199997 +82.400002 +82.529999 +83.720001 +83.110001 +83.260002 +83.870003 +84.879997 +83.339996 +84.169998 +84.260002 +81.080002 +81.589996 +82.779999 +82.489998 +84.160004 +85.230003 +85.580002 +85.349998 +84.690002 +86.849998 +86.379997 +85.830002 +85.519997 +85.5 +85.510002 +85.400002 +85.709999 +85.720001 +85.540001 +85.949997 +86.349998 +87.110001 +88.190002 +88.279999 +88.220001 +87.82 +88.080002 +89.599998 +88.349998 +90.139999 +90.099998 +90 +91.610001 +91.900002 +91.82 +92.330002 +94.059998 +93.919998 +92.739998 +95.010002 +94.260002 +91.779999 +88 +91.330002 +89.610001 +85.010002 +88.18 +89.129997 +89.830002 +90.809998 +92.660004 +92 +92.720001 +91.489998 +91.730003 +94.059998 +95.419998 +94.199997 +93.769997 +92.849998 +93.050003 diff --git a/decider.cpp b/decider.cpp new file mode 100644 index 0000000..4b5e54b --- /dev/null +++ b/decider.cpp @@ -0,0 +1,19 @@ +#include +#include "decider.h" + +macd_decider::macd_decider(std::size_t limit) + : prices(limit, .0), macd(limit, .0), signal(limit, .0), limit(limit) {} + +void macd_decider::process(double price) +{ + prices.add(price); + macd.add(ema(prices.begin(), prices.begin() + 12) - ema(prices.begin(), prices.begin() + 26)); + signal.add(ema(macd.begin(), macd.begin() + 9)); +} + +void macd_decider::reset() +{ + prices = buffer(limit, .0); + signal = buffer(limit, .0); + macd = buffer(limit, .0); +} diff --git a/decider.h b/decider.h new file mode 100644 index 0000000..6991e62 --- /dev/null +++ b/decider.h @@ -0,0 +1,106 @@ +#ifndef DECIDER_H_ +#define DECIDER_H_ + +#include "helpers.h" +#include "network.h" +#include +#include + +class decider { +public: + double start_money; + unsigned start_stock; + + virtual int decide(double price, double money, unsigned stock) = 0; + virtual void reset() = 0; + + virtual ~decider() { } +}; + +class macd_decider { +private: + std::size_t limit; + +protected: + buffer prices; + buffer macd; + buffer signal; + +public: + macd_decider(std::size_t limit = 1000); + + virtual void process(double price); + virtual void reset(); +}; + +template +class neural_decider : public decider, macd_decider { +public: + using network_t = network; + network_t network; + + double start_money; + unsigned start_stock; + + neural_decider() : network(), macd_decider() { } + neural_decider(typename network_t::normalizer_t normalizer) + : network(normalizer), macd_decider() { } + + virtual int decide(double price, double money, unsigned stock) + { + process(price); + + auto input = prepare(money, stock); + auto result = network.evaluate(input); + + double buy = result.get(0, 0); + double sell = result.get(1, 0); + + double amount = (buy - sell - .5)/1.5; + + return abs(buy - sell) <= .5 ? 0 : amount * start_stock / 10; + } + + virtual void reset() + { + this->reset(); + } + + virtual ~neural_decider() { } + +private: + typename network_t::input prepare(double money, unsigned stock) + { + vector state = { + { (money - start_money) / start_money }, + { (double)stock / this->start_stock } + }; + + vector prices; + vector tech; + + for (int j = 0; j < p; j++) { + prices.set(j, 0, this->prices[j]); + } + + int i = 0; + for (int j = 0; j < m; j++, i++) { + tech.set(i, 0, macd[j]); + } + + for (int j = 0; j < s; j++, i++) { + tech.set(i, 0, signal[j]); + } + + // prices are normalized in their domain + prices = normalize(prices); + // analytic data is normalized in its own domain + tech = normalize(tech); + + auto concated = concat(prices, tech); + + return concat(concated, state); + } +}; + +#endif diff --git a/helpers.h b/helpers.h new file mode 100644 index 0000000..541651e --- /dev/null +++ b/helpers.h @@ -0,0 +1,48 @@ +#ifndef HELPERS_H_ +#define HELPERS_H_ + +#include +#include + +using std::deque; + +template +T ema(iter begin, iter end) +{ + const std::size_t N = std::distance(begin, end); + const T a = T(1) - T(2) / T(N + 1); + T b = T(1); + + T nominator = 0, denominator = 0; + for(iter it = begin; it < end; it++) { + nominator += *it * b; + denominator += b; + + b *= a; + } + + return nominator / denominator; +} + +template +class buffer : public deque +{ + using deque::deque; + + std::size_t limit; + + public: + buffer(std::size_t limit) : limit(limit), deque(limit) {}; + buffer(std::size_t limit, const T& value) : limit(limit), deque(limit, value) {}; + + void add(const T& value) + { + if (this->size() >= limit) { + this->pop_back(); + } + + push_front(value); + } +}; + +#endif diff --git a/main.cpp b/main.cpp new file mode 100644 index 0000000..bd1d45d --- /dev/null +++ b/main.cpp @@ -0,0 +1,57 @@ +#include +#include +#include +#include +#include +#include + +double expavg(const std::vector &values, int start, int n) +{ + double a = 1 - 2./(n + 1); + + double nominator = 0., denominator = 0.; + double b = 1.; + + for (int i = 0; i < n; i++) { + nominator += b*values[start - i]; + denominator += b; + + b *= a; + } + + return nominator / denominator; +} + +int main(int argc, char **argv) +{ + int low = 12, high = 26, s = 9; + + if (argc >= 2) + low = std::atoi(argv[2]); + + if (argc >= 3) + high = std::atoi(argv[4]); + + if (argc >= 4) + s = std::atoi(argv[3]); + + std::vector prices; + double price; + + while (std::cin >> price) { + prices.push_back(price); + } + + std::vector macd(prices.size()); + std::vector signal(prices.size()); + + for (int i = 0; i < prices.size(); ++i) { + macd[i] = expavg(prices, i, std::min(i, low)) - expavg(prices, i, std::min(i, high)); + signal[i] = expavg(macd, i, std::min(i, s)); + } + + std::cout << "price,macd,signal,delta" << std::endl; + for (int i = 1; i < prices.size(); ++i) { + std::cout << prices[i] << "," << macd[i] << "," << signal[i] << "," << prices[i] - prices[i-1] << std::endl; + } +} diff --git a/matrix.h b/matrix.h new file mode 100644 index 0000000..f1dd306 --- /dev/null +++ b/matrix.h @@ -0,0 +1,235 @@ +#ifndef MATRIX_H_ +#define MATRIX_H_ + +#include +#include +#include + +template +class matrix +{ + T values[m*n]; + + public: + typedef matrix row_t; + typedef matrix column_t; + + matrix() + { + for (int i = 0; i < m; ++i) + for (int j = 0; j < n; j++) + values[i*n + j] = T(); + } + + matrix(std::initializer_list> list) + { + int i = 0, j = 0; + for (const auto& row : list) { + j = 0; + for (const auto& cell : row) { + set(i, j++, cell); + } + i++; + } + } + + T get(int i, int j) const + { + return values[i*n + j]; + } + + void set(int i, int j, T value) + { + values[i*n + j] = value; + } + + template matrix operator* (const matrix& rhs) const + { + matrix result; + + for (int i = 0; i < m; ++i) { + for(int j = 0; j < p; j++) { + T accumulator = 0; + for(int k = 0; k < n; k++) + accumulator += this->get(i, k) * rhs.get(k, j); + + result.set(i, j, accumulator); + } + } + + return result; + } + + matrix operator* (const T& rhs) const + { + matrix result; + + for (int i = 0; i < m; ++i) + for (int j = 0; j < m; ++j) + result.set(i, j, rhs * get(i, j)); + + return result; + } + + matrix transpose() const + { + matrix result; + + for (int i = 0; i < m; ++i) + for (int j = 0; j < m; ++j) + result.set(j, i, get(i, j)); + + + return result; + } + + matrix operator- () const + { + matrix result; + + for (int i = 0; i < m; ++i) + for (int j = 0; j < n; ++j) + result.set(i, j, -get(i, j)); + + return result; + } + + matrix operator- (const matrix& rhs) const + { + return *this + (-rhs); + } + + matrix operator- (const T& value) const + { + return *this + (-value); + } + + matrix operator+ (const matrix& rhs) const + { + matrix result; + + for (int i = 0; i < m; ++i) + for (int j = 0; j < n; ++j) + result.set(i, j, this->get(i, j) + rhs.get(i, j)); + + return result; + } + + matrix operator+ (const T& value) const + { + matrix result; + + for (int i = 0; i < m; ++i) + for (int j = 0; j < n; ++j) + result.set(this->get(i, j) + value); + + return result; + } + + column_t column(std::size_t j) + { + column_t result; + + for (int i = 0; i < m; ++i) { + result.set(i, 0, get(i, j)); + } + + return result; + } + + row_t row(std::size_t i) + { + row_t result; + + for (int j = 0; j < n; ++j) { + result.set(0, j, get(i, j)); + } + + return result; + } + + friend std::ostream& operator<< (std::ostream& stream, const matrix& matrix) + { + for (int i = 0; i < m; ++i) { + for (int j = 0; j < n; j++) { + stream << matrix.get(i, j) << " "; + } + stream << std::endl; + } + + return stream; + } +}; + +template matrix operator*(const T& lhs, const matrix& rhs) { + return rhs * lhs; +} + +template using vector = matrix; + +template void fill(matrix &mat, std::function filler) +{ + for (int i = 0; i < m; i++) + for (int j = 0; j < n; j++) + mat.set(i, j, filler(i, j)); +} + +template +vector concat(const vector &a, const vector &b) +{ + vector result; + + for (int i = 0; i < n; i++) + result.set(i, 0, a.get(i, 0)); + for (int i = 0; i < m; i++) + result.set(i+n, 0, a.get(i, 0)); + + return result; +} + +template +vector normalize(const vector &vec) +{ + T accumulator = T(); + + for (int i = 0; i < n; i++) { + T temp = vec.get(i, 0); + accumulator += temp * temp; + } + + accumulator = sqrt(accumulator); + std::function normalizer = [accumulator](const T& item) { return item / accumulator; }; + return map(vec, normalizer); +} + +template +matrix map(const matrix& matrix, std::function func) +{ + ::matrix result; + + for (int i = 0; i < m; i++) + for (int j = 0; j < n; j++) + result.set(i, j, func(matrix.get(i, j))); + + return result; +} + +template +matrix combine(const matrix& a, const matrix& b, std::function func) +{ + ::matrix result; + + for (int i = 0; i < m; i++) + for (int j = 0; j < n; j++) + result.set(i, j, func(a.get(i, j), b.get(i, j))); + + return result; +} + +template +matrix combine(const matrix& a, const matrix& b, T c, T d) +{ + return a*c + d*b; +} + +#endif diff --git a/network.h b/network.h new file mode 100644 index 0000000..51c7385 --- /dev/null +++ b/network.h @@ -0,0 +1,171 @@ +#ifndef NETWORK_H_ +#define NETWORK_H_ + +#include "matrix.h" +#include + +template +struct layer { + using filler_t = std::function; + using combiner_t = std::function; + + matrix weights; + vector bias; + + vector evaluate(vector input) + { + return weights * input - bias; + } + + void fill(filler_t weight_filler, filler_t bias_filler) + { + ::fill(weights, weight_filler); + ::fill(bias, bias_filler); + } + + void fill(filler_t filler) + { + // use same filler for both + fill(filler, filler); + } + + layer combine(const layer &rhs, combiner_t weight_combiner, combiner_t bias_combiner) + { + layer result; + + result.weights = ::combine(weights, rhs.weights, weight_combiner); + result.bias = ::combine(bias, rhs.bias, bias_combiner); + + return result; + } + + layer combine(const layer &rhs, combiner_t combiner) + { + return combine(rhs, combiner, combiner); + } +}; + +template struct layer_types; +template +struct layer_types : layer_types { }; + +template +struct layer_types<0, T, in, out, rest...> { + using type = layer; +}; + +template class network; + +template +class network { +protected: + layer current; + +public: + static const std::size_t layer_count = 1; + + using self = network; + + using output = vector; + using input = vector; + + using filler_t = typename layer::filler_t; + using combiner_t = typename layer::combiner_t; + using normalizer_t = std::function; + + template using layer_type = typename layer_types::type; + + normalizer_t normalizer; + + network(normalizer_t normalizer) : normalizer(normalizer) { } + network() : network([](const T& value) { return value; }) { }; + + output evaluate(input inp) + { + return map(current.evaluate(inp), normalizer); + } + + template layer_type& get() + { + return current; + } + + void fill(filler_t weights, filler_t bias) + { + current.fill(weights, bias); + } + + void fill(filler_t filler) + { + current.fill(filler); + } + + self combine(self& rhs, combiner_t weight_combiner, combiner_t bias_combiner) { + self result; + result.template get<0>() = get<0>().combine(rhs.template get<0>(), weight_combiner, bias_combiner); + + return result; + } + + self combine(self& rhs, combiner_t combiner) + { + return combine(rhs, combiner, combiner); + } +}; + +template +class network : public network { + using base = network; + using self = network; + + network subnetwork; + +public: + network(typename base::normalizer_t normalizer) : base(normalizer), subnetwork(normalizer) {} + network() : network([](const T& value) { return value; }) { }; + + + using output = typename network::output; + static const std::size_t layer_count = sizeof...(layers) + 1; + + template using layer_type = typename layer_types::type; + + template layer_type& get() + { + return subnetwork.template get(); + } + + template<> layer_type<0>& get<0>() + { + return base::template get<0>(); + } + + output evaluate(typename base::input inp) + { + auto result = base::evaluate(inp); + return subnetwork.evaluate(result); + } + + void fill(typename base::filler_t filler) + { + base::fill(filler); + subnetwork.fill(filler); + } + + void fill(typename base::filler_t weights, typename base::filler_t bias) + { + base::fill(weights, bias); + subnetwork.fill(weights, bias); + } + + self combine(self& rhs, typename base::combiner_t weight_combiner, typename base::combiner_t bias_combiner) { + self result; + + result.template get<0>() = get<0>().combine(rhs.template get<0>(), weight_combiner, bias_combiner); + result.subnetwork = subnetwork.combine(rhs.subnetwork); + + return result; + } +}; + +#endif diff --git a/sprawozdanie/macd.tex b/sprawozdanie/macd.tex new file mode 100644 index 0000000..4f430eb --- /dev/null +++ b/sprawozdanie/macd.tex @@ -0,0 +1,16 @@ +\begin{axis}[ + axis lines=center, no marks, + width=\linewidth, height=.66\linewidth, +] + \addplot table [x expr=\coordindex, y=price, col sep=comma] {\file}; +\end{axis} + +\begin{axis}[ + axis lines=center, no marks, + width=\linewidth, height=3cm, + hide y axis, +] + \addplot table [x expr=\coordindex, y=macd, col sep=comma] {\file}; + \addplot table [x expr=\coordindex, y=signal, col sep=comma] {\file}; + \addplot table [x expr=\coordindex, y=delta, col sep=comma] {\file}; +\end{axis} diff --git a/sprawozdanie/sprawozdanie.tex b/sprawozdanie/sprawozdanie.tex new file mode 100644 index 0000000..cf7e65c --- /dev/null +++ b/sprawozdanie/sprawozdanie.tex @@ -0,0 +1,61 @@ +\documentclass[]{article} +\usepackage[T1]{fontenc} +\usepackage{polski} +\usepackage[utf8]{inputenc} +\usepackage[margin=1.25in]{geometry} +\usepackage{alltt} +\usepackage{titling} +\usepackage{pdfpages} +\usepackage{float} +\usepackage{amsmath} +\usepackage{booktabs} +\usepackage{tabularx} +\usepackage{amstext} +\usepackage{pgfplots} +\usepackage{tikz} +\usepackage{xspace} +\usepackage{enumerate} +\usepackage{lmodern} +\usepackage{amsfonts} +\usepackage{mathtools} +\usepackage{alphalph} +\usepackage{algorithm} +\usepackage{algpseudocode} +\usepackage{wrapfig} +\usepackage[polish]{babel} +\usepackage{braket} +\usepackage{subcaption} + +\pgfplotsset{compat=1.15} + +\DeclarePairedDelimiter\ceil{\lceil}{\rceil} +\DeclarePairedDelimiter\floor{\lfloor}{\rfloor} + +\usetikzlibrary{decorations.pathmorphing, arrows.meta, positioning} +\usetikzlibrary{shapes.geometric, arrows} + +\pgfdeclarelayer{background} +\pgfdeclarelayer{foreground} +\pgfsetlayers{background,main,foreground} + +% opening +\title{Analiza Techniczna - MACD \\ \normalsize Projekt \#1 z \texttt{MN}} +\author{Kacper Donat} +\newenvironment{column}[1]{\noindent\begin{minipage}{#1\linewidth}}{\end{minipage}\vspace{.5\baselineskip}} + +\floatname{algorithm}{Program} + +\begin{document} + +\newcommand{\macd}[1]{\def\file{#1}\input{macd.tex}} + +\maketitle + +\begin{figure}[H] + \begin{tikzpicture} + \macd{msft.csv} + \end{tikzpicture} + \caption{XD} +\end{figure} + +\end{document} diff --git a/trainer.h b/trainer.h new file mode 100644 index 0000000..da46d23 --- /dev/null +++ b/trainer.h @@ -0,0 +1,99 @@ +#include +#include +#include +#include + +template +struct trained { + unsigned int id; + T decider; + + double monies; + unsigned stock; + + double result; +}; + +template +class trainer { + std::vector< trained* > trainees; + std::function factory; + + unsigned int id; + +public: + double money; + unsigned stock; + + trainer(double money, unsigned stock, std::size_t n, std::function factory) + : factory(factory), id(0), money(money), stock(stock) + { + add(n); + } + + void add(std::size_t n, std::function factory) + { + for(std::size_t i = 0; i < n; i++) { + trained *trainee = new trained(); + trainee->id = ++id; + trainee->result = 0.0; + trainee->decider = factory(); + + trainees.push_back(trainee); + } + } + + void add(std::size_t n) + { + add(n, factory); + } + + void test(std::istream& input) + { + for (auto trainee : trainees) { + trainee->monies = money; + trainee->stock = stock; + + trainee->decider.start_money = money; + trainee->decider.start_stock = stock; + } + + double price, start; + input >> price; + start = price*stock + money; + + do { + for (auto trainee : trainees) { + auto decision = trainee->decider.decide(price, trainee->monies, trainee->stock); + auto current = price*trainee->stock + trainee->monies; + auto max_credit = std::max(current * 0.05, -1e4); + + /* std::cout << "D: " << decision << " C: " << current << " P: " << price << " MC: " << max_credit << std::endl; */ + if (decision > 0 && trainee->monies - decision*price < -max_credit) { + decision = floor((trainee->monies + max_credit) / price); + } + + if (decision < 0 && -decision > trainee->stock) { + decision = -trainee->stock; + } + + trainee->stock += decision; + trainee->monies -= price*decision; + } + } while (input >> price); + + auto hodl = price * stock + money; + std::cout << "Zakonczono testy " << trainees.size() << " przypadkow." << std::endl; + std::cout << "HODL: " << hodl << " START: " << start << std::endl; + std::cout << "-----------------------" << std::endl; + + std::sort(trainees.begin(), trainees.end(), [=](trained *a, trained *b){ + return (a->monies + a->stock * price) > (b->monies + b->stock * price); + }); + + for (auto trainee : trainees) { + auto earned = trainee->monies + trainee->stock * price; + std::cout << "#" << trainee->id << ": " << earned << " [" << earned - hodl << "] " << trainee->stock << " akcji, " << trainee->monies << " gelda w banku. " << std::endl; + } + } +}; diff --git a/wtf.cpp b/wtf.cpp new file mode 100644 index 0000000..c789b49 --- /dev/null +++ b/wtf.cpp @@ -0,0 +1,52 @@ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "argh.h" +#include "matrix.h" +#include "network.h" +#include "decider.h" +#include "trainer.h" + +int main(int argc, char* argv[]) +{ + argh::parser args; + args.add_params({"-m", "--money"}); + args.add_params({"-s", "--stock"}); + args.add_params({"-p", "--population"}); + args.parse(argc, argv); + + double money; + unsigned stock, population; + + args({ "m", "money" }, 1000.) >> money; + args({ "s", "stock" }, 1000) >> stock; + args({ "p", "population" }, 25) >> population; + + std::uniform_real_distribution distribution(-1.0, 1.0); + std::default_random_engine random_engine; + random_engine.seed(std::time(0)); + + std::function randomizer = [&](const int& i, const int& j) -> double { + return distribution(random_engine); + }; + + std::function normalizer = [](const double& result) -> double { return erf(result); }; + + using current_decider = neural_decider<24, 12, 12, 32, 16>; + + std::function factory = [&]() -> current_decider { + current_decider decider(normalizer); + decider.network.fill(randomizer); + + return decider; + }; + + trainer train(money, stock, population, factory); + train.test(std::cin); +}