icekontroi

Untitled

Sep 22nd, 2017
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 32.07 KB | None | 0 0
  1. package RSX;
  2.  
  3. import smile.regression.RandomForest;
  4.  
  5. import java.text.DecimalFormat;
  6. import java.util.ArrayList;
  7. import java.util.Collections;
  8. import java.util.Date;
  9. import java.util.HashMap;
  10.  
  11. public class SimpleForest {
  12.  
  13. static final int nTrees = 500, nNodes = 500, sNodes = 2;
  14.  
  15. static final String data = "[{\"ts\":1505498400000,\"buyingPrice\":67291106,\"buyingCompleted\":21,\"sellingPrice\":67249734,\"sellingCompleted\":15,\"overallPrice\":67273868,\"overallCompleted\":36},{\"ts\":1505502000000,\"buyingPrice\":67339698,\"buyingCompleted\":21,\"sellingPrice\":67368525,\"sellingCompleted\":17,\"overallPrice\":67352594,\"overallCompleted\":38},{\"ts\":1505505600000,\"buyingPrice\":67365979,\"buyingCompleted\":17,\"sellingPrice\":67257709,\"sellingCompleted\":16,\"overallPrice\":67313484,\"overallCompleted\":33},{\"ts\":1505509200000,\"buyingPrice\":67704883,\"buyingCompleted\":22,\"sellingPrice\":67497418,\"sellingCompleted\":17,\"overallPrice\":67614450,\"overallCompleted\":39},{\"ts\":1505512800000,\"buyingPrice\":67640488,\"buyingCompleted\":23,\"sellingPrice\":67649811,\"sellingCompleted\":24,\"overallPrice\":67645249,\"overallCompleted\":47},{\"ts\":1505516400000,\"buyingPrice\":67790211,\"buyingCompleted\":29,\"sellingPrice\":67745577,\"sellingCompleted\":25,\"overallPrice\":67769547,\"overallCompleted\":54},{\"ts\":1505520000000,\"buyingPrice\":67950721,\"buyingCompleted\":16,\"sellingPrice\":67955592,\"sellingCompleted\":12,\"overallPrice\":67952809,\"overallCompleted\":28},{\"ts\":1505523600000,\"buyingPrice\":67772360,\"buyingCompleted\":39,\"sellingPrice\":67799095,\"sellingCompleted\":33,\"overallPrice\":67784613,\"overallCompleted\":72},{\"ts\":1505527200000,\"buyingPrice\":67914287,\"buyingCompleted\":23,\"sellingPrice\":67968978,\"sellingCompleted\":22,\"overallPrice\":67941025,\"overallCompleted\":45},{\"ts\":1505530800000,\"buyingPrice\":68154988,\"buyingCompleted\":21,\"sellingPrice\":68101173,\"sellingCompleted\":27,\"overallPrice\":68124717,\"overallCompleted\":48},{\"ts\":1505534400000,\"buyingPrice\":67883364,\"buyingCompleted\":13,\"sellingPrice\":67868666,\"sellingCompleted\":14,\"overallPrice\":67875743,\"overallCompleted\":27},{\"ts\":1505538000000,\"buyingPrice\":68056572,\"buyingCompleted\":11,\"sellingPrice\":67916001,\"sellingCompleted\":13,\"overallPrice\":67980429,\"overallCompleted\":24},{\"ts\":1505541600000,\"buyingPrice\":67981088,\"buyingCompleted\":14,\"sellingPrice\":67953400,\"sellingCompleted\":12,\"overallPrice\":67968309,\"overallCompleted\":26},{\"ts\":1505545200000,\"buyingPrice\":68082160,\"buyingCompleted\":17,\"sellingPrice\":67950936,\"sellingCompleted\":15,\"overallPrice\":68020649,\"overallCompleted\":32},{\"ts\":1505548800000,\"buyingPrice\":68401292,\"buyingCompleted\":26,\"sellingPrice\":68234434,\"sellingCompleted\":29,\"overallPrice\":68313312,\"overallCompleted\":55},{\"ts\":1505552400000,\"buyingPrice\":69201556,\"buyingCompleted\":18,\"sellingPrice\":68740222,\"sellingCompleted\":18,\"overallPrice\":68970889,\"overallCompleted\":36},{\"ts\":1505556000000,\"buyingPrice\":68895346,\"buyingCompleted\":26,\"sellingPrice\":68916840,\"sellingCompleted\":25,\"overallPrice\":68905883,\"overallCompleted\":51},{\"ts\":1505559600000,\"buyingPrice\":68862076,\"buyingCompleted\":16,\"sellingPrice\":68805466,\"sellingCompleted\":25,\"overallPrice\":68827558,\"overallCompleted\":41},{\"ts\":1505563200000,\"buyingPrice\":68998729,\"buyingCompleted\":26,\"sellingPrice\":68941608,\"sellingCompleted\":28,\"overallPrice\":68969110,\"overallCompleted\":54},{\"ts\":1505566800000,\"buyingPrice\":68951297,\"buyingCompleted\":20,\"sellingPrice\":68979438,\"sellingCompleted\":25,\"overallPrice\":68966931,\"overallCompleted\":45},{\"ts\":1505570400000,\"buyingPrice\":69028667,\"buyingCompleted\":17,\"sellingPrice\":69065150,\"sellingCompleted\":17,\"overallPrice\":69046908,\"overallCompleted\":34},{\"ts\":1505574000000,\"buyingPrice\":69071148,\"buyingCompleted\":23,\"sellingPrice\":69041553,\"sellingCompleted\":25,\"overallPrice\":69055734,\"overallCompleted\":48},{\"ts\":1505577600000,\"buyingPrice\":69002329,\"buyingCompleted\":29,\"sellingPrice\":68984750,\"sellingCompleted\":25,\"overallPrice\":68994190,\"overallCompleted\":54},{\"ts\":1505581200000,\"buyingPrice\":68971168,\"buyingCompleted\":21,\"sellingPrice\":68962499,\"sellingCompleted\":10,\"overallPrice\":68968372,\"overallCompleted\":31},{\"ts\":1505584800000,\"buyingPrice\":68976152,\"buyingCompleted\":26,\"sellingPrice\":68931666,\"sellingCompleted\":27,\"overallPrice\":68953489,\"overallCompleted\":53},{\"ts\":1505588400000,\"buyingPrice\":68936487,\"buyingCompleted\":31,\"sellingPrice\":69032118,\"sellingCompleted\":26,\"overallPrice\":68980108,\"overallCompleted\":57},{\"ts\":1505592000000,\"buyingPrice\":68922761,\"buyingCompleted\":14,\"sellingPrice\":68887154,\"sellingCompleted\":20,\"overallPrice\":68901815,\"overallCompleted\":34},{\"ts\":1505595600000,\"buyingPrice\":68849971,\"buyingCompleted\":42,\"sellingPrice\":68842780,\"sellingCompleted\":35,\"overallPrice\":68846703,\"overallCompleted\":77},{\"ts\":1505599200000,\"buyingPrice\":68799410,\"buyingCompleted\":32,\"sellingPrice\":68752677,\"sellingCompleted\":34,\"overallPrice\":68775335,\"overallCompleted\":66},{\"ts\":1505602800000,\"buyingPrice\":68637527,\"buyingCompleted\":19,\"sellingPrice\":68727502,\"sellingCompleted\":27,\"overallPrice\":68690339,\"overallCompleted\":46},{\"ts\":1505606400000,\"buyingPrice\":68732509,\"buyingCompleted\":24,\"sellingPrice\":68744004,\"sellingCompleted\":26,\"overallPrice\":68738486,\"overallCompleted\":50},{\"ts\":1505610000000,\"buyingPrice\":68636077,\"buyingCompleted\":16,\"sellingPrice\":68669064,\"sellingCompleted\":21,\"overallPrice\":68654800,\"overallCompleted\":37},{\"ts\":1505613600000,\"buyingPrice\":68569680,\"buyingCompleted\":25,\"sellingPrice\":68420768,\"sellingCompleted\":35,\"overallPrice\":68482815,\"overallCompleted\":60},{\"ts\":1505617200000,\"buyingPrice\":68457409,\"buyingCompleted\":19,\"sellingPrice\":68379270,\"sellingCompleted\":26,\"overallPrice\":68412262,\"overallCompleted\":45},{\"ts\":1505620800000,\"buyingPrice\":68359619,\"buyingCompleted\":17,\"sellingPrice\":68368010,\"sellingCompleted\":17,\"overallPrice\":68363815,\"overallCompleted\":34},{\"ts\":1505624400000,\"buyingPrice\":68383170,\"buyingCompleted\":27,\"sellingPrice\":68321202,\"sellingCompleted\":21,\"overallPrice\":68356059,\"overallCompleted\":48},{\"ts\":1505628000000,\"buyingPrice\":68298632,\"buyingCompleted\":18,\"sellingPrice\":68284411,\"sellingCompleted\":18,\"overallPrice\":68291521,\"overallCompleted\":36},{\"ts\":1505631600000,\"buyingPrice\":68235627,\"buyingCompleted\":18,\"sellingPrice\":68215178,\"sellingCompleted\":22,\"overallPrice\":68224380,\"overallCompleted\":40},{\"ts\":1505635200000,\"buyingPrice\":68227104,\"buyingCompleted\":23,\"sellingPrice\":68186406,\"sellingCompleted\":28,\"overallPrice\":68204760,\"overallCompleted\":51},{\"ts\":1505638800000,\"buyingPrice\":68238857,\"buyingCompleted\":35,\"sellingPrice\":68204167,\"sellingCompleted\":25,\"overallPrice\":68224403,\"overallCompleted\":60},{\"ts\":1505642400000,\"buyingPrice\":68312201,\"buyingCompleted\":41,\"sellingPrice\":68351381,\"sellingCompleted\":25,\"overallPrice\":68327042,\"overallCompleted\":66},{\"ts\":1505646000000,\"buyingPrice\":68322499,\"buyingCompleted\":24,\"sellingPrice\":68300207,\"sellingCompleted\":29,\"overallPrice\":68310302,\"overallCompleted\":53},{\"ts\":1505649600000,\"buyingPrice\":68331325,\"buyingCompleted\":15,\"sellingPrice\":68284027,\"sellingCompleted\":21,\"overallPrice\":68303734,\"overallCompleted\":36},{\"ts\":1505653200000,\"buyingPrice\":68327518,\"buyingCompleted\":25,\"sellingPrice\":68263265,\"sellingCompleted\":18,\"overallPrice\":68300621,\"overallCompleted\":43},{\"ts\":1505656800000,\"buyingPrice\":68290957,\"buyingCompleted\":15,\"sellingPrice\":68222124,\"sellingCompleted\":20,\"overallPrice\":68251624,\"overallCompleted\":35},{\"ts\":1505660400000,\"buyingPrice\":68304358,\"buyingCompleted\":22,\"sellingPrice\":68272367,\"sellingCompleted\":23,\"overallPrice\":68288007,\"overallCompleted\":45},{\"ts\":1505664000000,\"buyingPrice\":68196101,\"buyingCompleted\":13,\"sellingPrice\":68163317,\"sellingCompleted\":22,\"overallPrice\":68175494,\"overallCompleted\":35},{\"ts\":1505667600000,\"buyingPrice\":68134116,\"buyingCompleted\":32,\"sellingPrice\":68129299,\"sellingCompleted\":24,\"overallPrice\":68132051,\"overallCompleted\":56},{\"ts\":1505671200000,\"buyingPrice\":68158529,\"buyingCompleted\":24,\"sellingPrice\":68098034,\"sellingCompleted\":22,\"overallPrice\":68129596,\"overallCompleted\":46},{\"ts\":1505674800000,\"buyingPrice\":68155787,\"buyingCompleted\":12,\"sellingPrice\":68091504,\"sellingCompleted\":16,\"overallPrice\":68119054,\"overallCompleted\":28},{\"ts\":1505678400000,\"buyingPrice\":68225553,\"buyingCompleted\":16,\"sellingPrice\":68078633,\"sellingCompleted\":16,\"overallPrice\":68152093,\"overallCompleted\":32},{\"ts\":1505682000000,\"buyingPrice\":68177423,\"buyingCompleted\":22,\"sellingPrice\":68123670,\"sellingCompleted\":21,\"overallPrice\":68151172,\"overallCompleted\":43},{\"ts\":1505685600000,\"buyingPrice\":68176378,\"buyingCompleted\":15,\"sellingPrice\":68199538,\"sellingCompleted\":18,\"overallPrice\":68189011,\"overallCompleted\":33},{\"ts\":1505689200000,\"buyingPrice\":68184906,\"buyingCompleted\":19,\"sellingPrice\":68145930,\"sellingCompleted\":22,\"overallPrice\":68163992,\"overallCompleted\":41},{\"ts\":1505692800000,\"buyingPrice\":68148996,\"buyingCompleted\":23,\"sellingPrice\":68149424,\"sellingCompleted\":27,\"overallPrice\":68149227,\"overallCompleted\":50},{\"ts\":1505696400000,\"buyingPrice\":68164989,\"buyingCompleted\":32,\"sellingPrice\":68167608,\"sellingCompleted\":30,\"overallPrice\":68166256,\"overallCompleted\":62},{\"ts\":1505700000000,\"buyingPrice\":68165408,\"buyingCompleted\":18,\"sellingPrice\":67938260,\"sellingCompleted\":22,\"overallPrice\":68040477,\"overallCompleted\":40},{\"ts\":1505703600000,\"buyingPrice\":68147039,\"buyingCompleted\":31,\"sellingPrice\":68089221,\"sellingCompleted\":25,\"overallPrice\":68121228,\"overallCompleted\":56},{\"ts\":1505707200000,\"buyingPrice\":68092762,\"buyingCompleted\":23,\"sellingPrice\":68116196,\"sellingCompleted\":18,\"overallPrice\":68103050,\"overallCompleted\":41},{\"ts\":1505710800000,\"buyingPrice\":68030814,\"buyingCompleted\":24,\"sellingPrice\":68015022,\"sellingCompleted\":27,\"overallPrice\":68022453,\"overallCompleted\":51},{\"ts\":1505714400000,\"buyingPrice\":68072145,\"buyingCompleted\":19,\"sellingPrice\":68142462,\"sellingCompleted\":30,\"overallPrice\":68115196,\"overallCompleted\":49},{\"ts\":1505718000000,\"buyingPrice\":67991903,\"buyingCompleted\":23,\"sellingPrice\":68030588,\"sellingCompleted\":27,\"overallPrice\":68012793,\"overallCompleted\":50},{\"ts\":1505721600000,\"buyingPrice\":68035021,\"buyingCompleted\":10,\"sellingPrice\":68048411,\"sellingCompleted\":13,\"overallPrice\":68042589,\"overallCompleted\":23},{\"ts\":1505725200000,\"buyingPrice\":67977156,\"buyingCompleted\":19,\"sellingPrice\":67911402,\"sellingCompleted\":12,\"overallPrice\":67951702,\"overallCompleted\":31},{\"ts\":1505728800000,\"buyingPrice\":67867457,\"buyingCompleted\":13,\"sellingPrice\":67838636,\"sellingCompleted\":11,\"overallPrice\":67854248,\"overallCompleted\":24},{\"ts\":1505732400000,\"buyingPrice\":67870042,\"buyingCompleted\":24,\"sellingPrice\":67815594,\"sellingCompleted\":24,\"overallPrice\":67842818,\"overallCompleted\":48},{\"ts\":1505736000000,\"buyingPrice\":67834132,\"buyingCompleted\":18,\"sellingPrice\":67812405,\"sellingCompleted\":22,\"overallPrice\":67822182,\"overallCompleted\":40},{\"ts\":1505739600000,\"buyingPrice\":67769454,\"buyingCompleted\":26,\"sellingPrice\":67800649,\"sellingCompleted\":30,\"overallPrice\":67786166,\"overallCompleted\":56},{\"ts\":1505743200000,\"buyingPrice\":67777273,\"buyingCompleted\":19,\"sellingPrice\":67782766,\"sellingCompleted\":18,\"overallPrice\":67779945,\"overallCompleted\":37},{\"ts\":1505746800000,\"buyingPrice\":67749802,\"buyingCompleted\":18,\"sellingPrice\":67728165,\"sellingCompleted\":19,\"overallPrice\":67738691,\"overallCompleted\":37},{\"ts\":1505750400000,\"buyingPrice\":67715695,\"buyingCompleted\":28,\"sellingPrice\":67724357,\"sellingCompleted\":23,\"overallPrice\":67719602,\"overallCompleted\":51},{\"ts\":1505754000000,\"buyingPrice\":67679642,\"buyingCompleted\":14,\"sellingPrice\":67647097,\"sellingCompleted\":15,\"overallPrice\":67662809,\"overallCompleted\":29},{\"ts\":1505757600000,\"buyingPrice\":67629338,\"buyingCompleted\":24,\"sellingPrice\":67688948,\"sellingCompleted\":20,\"overallPrice\":67656434,\"overallCompleted\":44},{\"ts\":1505761200000,\"buyingPrice\":67600901,\"buyingCompleted\":19,\"sellingPrice\":67610296,\"sellingCompleted\":20,\"overallPrice\":67605719,\"overallCompleted\":39},{\"ts\":1505764800000,\"buyingPrice\":67625387,\"buyingCompleted\":28,\"sellingPrice\":67617460,\"sellingCompleted\":29,\"overallPrice\":67621354,\"overallCompleted\":57},{\"ts\":1505768400000,\"buyingPrice\":67587506,\"buyingCompleted\":24,\"sellingPrice\":67554559,\"sellingCompleted\":27,\"overallPrice\":67570064,\"overallCompleted\":51},{\"ts\":1505772000000,\"buyingPrice\":67577283,\"buyingCompleted\":24,\"sellingPrice\":67593535,\"sellingCompleted\":28,\"overallPrice\":67586034,\"overallCompleted\":52},{\"ts\":1505775600000,\"buyingPrice\":67591643,\"buyingCompleted\":22,\"sellingPrice\":67587393,\"sellingCompleted\":15,\"overallPrice\":67589920,\"overallCompleted\":37},{\"ts\":1505779200000,\"buyingPrice\":67552932,\"buyingCompleted\":16,\"sellingPrice\":67537743,\"sellingCompleted\":16,\"overallPrice\":67545337,\"overallCompleted\":32},{\"ts\":1505782800000,\"buyingPrice\":67563507,\"buyingCompleted\":14,\"sellingPrice\":67489918,\"sellingCompleted\":17,\"overallPrice\":67523152,\"overallCompleted\":31},{\"ts\":1505786400000,\"buyingPrice\":67505171,\"buyingCompleted\":13,\"sellingPrice\":67408270,\"sellingCompleted\":16,\"overallPrice\":67451709,\"overallCompleted\":29},{\"ts\":1505790000000,\"buyingPrice\":67453442,\"buyingCompleted\":15,\"sellingPrice\":67410762,\"sellingCompleted\":26,\"overallPrice\":67426377,\"overallCompleted\":41},{\"ts\":1505793600000,\"buyingPrice\":67491681,\"buyingCompleted\":22,\"sellingPrice\":67404148,\"sellingCompleted\":21,\"overallPrice\":67448933,\"overallCompleted\":43},{\"ts\":1505797200000,\"buyingPrice\":67425541,\"buyingCompleted\":21,\"sellingPrice\":67439468,\"sellingCompleted\":23,\"overallPrice\":67432821,\"overallCompleted\":44},{\"ts\":1505800800000,\"buyingPrice\":67385568,\"buyingCompleted\":29,\"sellingPrice\":67340745,\"sellingCompleted\":24,\"overallPrice\":67365271,\"overallCompleted\":53},{\"ts\":1505804400000,\"buyingPrice\":67345091,\"buyingCompleted\":14,\"sellingPrice\":67291790,\"sellingCompleted\":19,\"overallPrice\":67314402,\"overallCompleted\":33},{\"ts\":1505808000000,\"buyingPrice\":67332416,\"buyingCompleted\":6,\"sellingPrice\":67259493,\"sellingCompleted\":6,\"overallPrice\":67295955,\"overallCompleted\":12},{\"ts\":1505811600000,\"buyingPrice\":67264941,\"buyingCompleted\":9,\"sellingPrice\":67250550,\"sellingCompleted\":20,\"overallPrice\":67255016,\"overallCompleted\":29},{\"ts\":1505815200000,\"buyingPrice\":67197888,\"buyingCompleted\":8,\"sellingPrice\":67524112,\"sellingCompleted\":10,\"overallPrice\":67379123,\"overallCompleted\":18},{\"ts\":1505818800000,\"buyingPrice\":67115982,\"buyingCompleted\":24,\"sellingPrice\":67098536,\"sellingCompleted\":21,\"overallPrice\":67107841,\"overallCompleted\":45},{\"ts\":1505822400000,\"buyingPrice\":67144877,\"buyingCompleted\":17,\"sellingPrice\":67148134,\"sellingCompleted\":22,\"overallPrice\":67146714,\"overallCompleted\":39},{\"ts\":1505826000000,\"buyingPrice\":67068402,\"buyingCompleted\":25,\"sellingPrice\":67088784,\"sellingCompleted\":20,\"overallPrice\":67077461,\"overallCompleted\":45},{\"ts\":1505829600000,\"buyingPrice\":67056143,\"buyingCompleted\":22,\"sellingPrice\":67066721,\"sellingCompleted\":23,\"overallPrice\":67061549,\"overallCompleted\":45},{\"ts\":1505833200000,\"buyingPrice\":67040892,\"buyingCompleted\":16,\"sellingPrice\":67016554,\"sellingCompleted\":20,\"overallPrice\":67027371,\"overallCompleted\":36},{\"ts\":1505836800000,\"buyingPrice\":67010800,\"buyingCompleted\":17,\"sellingPrice\":66949710,\"sellingCompleted\":17,\"overallPrice\":66980255,\"overallCompleted\":34},{\"ts\":1505840400000,\"buyingPrice\":66989704,\"buyingCompleted\":20,\"sellingPrice\":66984826,\"sellingCompleted\":23,\"overallPrice\":66987095,\"overallCompleted\":43},{\"ts\":1505844000000,\"buyingPrice\":66990639,\"buyingCompleted\":15,\"sellingPrice\":66958488,\"sellingCompleted\":12,\"overallPrice\":66976350,\"overallCompleted\":27},{\"ts\":1505847600000,\"buyingPrice\":66964892,\"buyingCompleted\":20,\"sellingPrice\":66963585,\"sellingCompleted\":27,\"overallPrice\":66964141,\"overallCompleted\":47},{\"ts\":1505851200000,\"buyingPrice\":66989722,\"buyingCompleted\":16,\"sellingPrice\":66967996,\"sellingCompleted\":16,\"overallPrice\":66978859,\"overallCompleted\":32},{\"ts\":1505854800000,\"buyingPrice\":66936266,\"buyingCompleted\":15,\"sellingPrice\":66920176,\"sellingCompleted\":17,\"overallPrice\":66927718,\"overallCompleted\":32},{\"ts\":1505858400000,\"buyingPrice\":66909148,\"buyingCompleted\":16,\"sellingPrice\":66897113,\"sellingCompleted\":20,\"overallPrice\":66902462,\"overallCompleted\":36},{\"ts\":1505862000000,\"buyingPrice\":66888221,\"buyingCompleted\":26,\"sellingPrice\":66884750,\"sellingCompleted\":21,\"overallPrice\":66886670,\"overallCompleted\":47},{\"ts\":1505865600000,\"buyingPrice\":66736928,\"buyingCompleted\":20,\"sellingPrice\":66733839,\"sellingCompleted\":18,\"overallPrice\":66735465,\"overallCompleted\":38},{\"ts\":1505869200000,\"buyingPrice\":66745540,\"buyingCompleted\":23,\"sellingPrice\":66734872,\"sellingCompleted\":21,\"overallPrice\":66740448,\"overallCompleted\":44},{\"ts\":1505872800000,\"buyingPrice\":66718035,\"buyingCompleted\":28,\"sellingPrice\":66705013,\"sellingCompleted\":29,\"overallPrice\":66711410,\"overallCompleted\":57},{\"ts\":1505876400000,\"buyingPrice\":66819743,\"buyingCompleted\":22,\"sellingPrice\":66782335,\"sellingCompleted\":18,\"overallPrice\":66802909,\"overallCompleted\":40},{\"ts\":1505880000000,\"buyingPrice\":66764105,\"buyingCompleted\":28,\"sellingPrice\":66744577,\"sellingCompleted\":27,\"overallPrice\":66754519,\"overallCompleted\":55},{\"ts\":1505883600000,\"buyingPrice\":66798655,\"buyingCompleted\":22,\"sellingPrice\":66781933,\"sellingCompleted\":22,\"overallPrice\":66790294,\"overallCompleted\":44},{\"ts\":1505887200000,\"buyingPrice\":66799999,\"buyingCompleted\":14,\"sellingPrice\":66773021,\"sellingCompleted\":18,\"overallPrice\":66784824,\"overallCompleted\":32},{\"ts\":1505890800000,\"buyingPrice\":66801933,\"buyingCompleted\":15,\"sellingPrice\":66818111,\"sellingCompleted\":17,\"overallPrice\":66810528,\"overallCompleted\":32},{\"ts\":1505894400000,\"buyingPrice\":66838215,\"buyingCompleted\":11,\"sellingPrice\":66751889,\"sellingCompleted\":12,\"overallPrice\":66793175,\"overallCompleted\":23},{\"ts\":1505898000000,\"buyingPrice\":66753643,\"buyingCompleted\":8,\"sellingPrice\":66734031,\"sellingCompleted\":14,\"overallPrice\":66741163,\"overallCompleted\":22},{\"ts\":1505901600000,\"buyingPrice\":66738994,\"buyingCompleted\":7,\"sellingPrice\":66700925,\"sellingCompleted\":14,\"overallPrice\":66713615,\"overallCompleted\":21},{\"ts\":1505905200000,\"buyingPrice\":66762413,\"buyingCompleted\":17,\"sellingPrice\":66674911,\"sellingCompleted\":22,\"overallPrice\":66713053,\"overallCompleted\":39},{\"ts\":1505908800000,\"buyingPrice\":66829325,\"buyingCompleted\":13,\"sellingPrice\":66758493,\"sellingCompleted\":11,\"overallPrice\":66796861,\"overallCompleted\":24},{\"ts\":1505912400000,\"buyingPrice\":66802853,\"buyingCompleted\":23,\"sellingPrice\":66785549,\"sellingCompleted\":13,\"overallPrice\":66796604,\"overallCompleted\":36},{\"ts\":1505916000000,\"buyingPrice\":66839989,\"buyingCompleted\":9,\"sellingPrice\":66741479,\"sellingCompleted\":12,\"overallPrice\":66783698,\"overallCompleted\":21},{\"ts\":1505919600000,\"buyingPrice\":66751029,\"buyingCompleted\":17,\"sellingPrice\":66696239,\"sellingCompleted\":13,\"overallPrice\":66727287,\"overallCompleted\":30},{\"ts\":1505923200000,\"buyingPrice\":66750724,\"buyingCompleted\":21,\"sellingPrice\":66724857,\"sellingCompleted\":17,\"overallPrice\":66739152,\"overallCompleted\":38},{\"ts\":1505926800000,\"buyingPrice\":66723552,\"buyingCompleted\":17,\"sellingPrice\":66724857,\"sellingCompleted\":17,\"overallPrice\":66724204,\"overallCompleted\":34},{\"ts\":1505930400000,\"buyingPrice\":66707807,\"buyingCompleted\":12,\"sellingPrice\":66678534,\"sellingCompleted\":10,\"overallPrice\":66694501,\"overallCompleted\":22},{\"ts\":1505934000000,\"buyingPrice\":66712882,\"buyingCompleted\":18,\"sellingPrice\":66683158,\"sellingCompleted\":14,\"overallPrice\":66699877,\"overallCompleted\":32},{\"ts\":1505937600000,\"buyingPrice\":66738282,\"buyingCompleted\":26,\"sellingPrice\":66715340,\"sellingCompleted\":20,\"overallPrice\":66728307,\"overallCompleted\":46},{\"ts\":1505941200000,\"buyingPrice\":66780099,\"buyingCompleted\":31,\"sellingPrice\":66811905,\"sellingCompleted\":23,\"overallPrice\":66793646,\"overallCompleted\":54},{\"ts\":1505944800000,\"buyingPrice\":66728264,\"buyingCompleted\":33,\"sellingPrice\":66712349,\"sellingCompleted\":35,\"overallPrice\":66720072,\"overallCompleted\":68},{\"ts\":1505948400000,\"buyingPrice\":66681833,\"buyingCompleted\":14,\"sellingPrice\":66673950,\"sellingCompleted\":27,\"overallPrice\":66676642,\"overallCompleted\":41},{\"ts\":1505952000000,\"buyingPrice\":66699919,\"buyingCompleted\":22,\"sellingPrice\":66659320,\"sellingCompleted\":17,\"overallPrice\":66682222,\"overallCompleted\":39},{\"ts\":1505955600000,\"buyingPrice\":66727107,\"buyingCompleted\":19,\"sellingPrice\":66666214,\"sellingCompleted\":10,\"overallPrice\":66706109,\"overallCompleted\":29},{\"ts\":1505959200000,\"buyingPrice\":66659896,\"buyingCompleted\":16,\"sellingPrice\":66638646,\"sellingCompleted\":20,\"overallPrice\":66648091,\"overallCompleted\":36},{\"ts\":1505962800000,\"buyingPrice\":66559789,\"buyingCompleted\":19,\"sellingPrice\":66531577,\"sellingCompleted\":26,\"overallPrice\":66543489,\"overallCompleted\":45},{\"ts\":1505966400000,\"buyingPrice\":66651633,\"buyingCompleted\":20,\"sellingPrice\":66606250,\"sellingCompleted\":24,\"overallPrice\":66626879,\"overallCompleted\":44},{\"ts\":1505970000000,\"buyingPrice\":66575099,\"buyingCompleted\":20,\"sellingPrice\":66524665,\"sellingCompleted\":18,\"overallPrice\":66551209,\"overallCompleted\":38},{\"ts\":1505973600000,\"buyingPrice\":66580114,\"buyingCompleted\":31,\"sellingPrice\":66561276,\"sellingCompleted\":22,\"overallPrice\":66572294,\"overallCompleted\":53},{\"ts\":1505977200000,\"buyingPrice\":66559555,\"buyingCompleted\":16,\"sellingPrice\":66533780,\"sellingCompleted\":17,\"overallPrice\":66546277,\"overallCompleted\":33},{\"ts\":1505980800000,\"buyingPrice\":66558845,\"buyingCompleted\":20,\"sellingPrice\":66562824,\"sellingCompleted\":24,\"overallPrice\":66561015,\"overallCompleted\":44},{\"ts\":1505984400000,\"buyingPrice\":66671177,\"buyingCompleted\":13,\"sellingPrice\":66635879,\"sellingCompleted\":21,\"overallPrice\":66649375,\"overallCompleted\":34},{\"ts\":1505988000000,\"buyingPrice\":66649499,\"buyingCompleted\":19,\"sellingPrice\":66604763,\"sellingCompleted\":22,\"overallPrice\":66625494,\"overallCompleted\":41},{\"ts\":1505991600000,\"buyingPrice\":66647464,\"buyingCompleted\":19,\"sellingPrice\":66653329,\"sellingCompleted\":15,\"overallPrice\":66650052,\"overallCompleted\":34},{\"ts\":1505995200000,\"buyingPrice\":66671131,\"buyingCompleted\":18,\"sellingPrice\":66654552,\"sellingCompleted\":17,\"overallPrice\":66663078,\"overallCompleted\":35},{\"ts\":1505998800000,\"buyingPrice\":66703997,\"buyingCompleted\":9,\"sellingPrice\":66635733,\"sellingCompleted\":22,\"overallPrice\":66655551,\"overallCompleted\":31},{\"ts\":1506002400000,\"buyingPrice\":66685411,\"buyingCompleted\":21,\"sellingPrice\":66631686,\"sellingCompleted\":16,\"overallPrice\":66662179,\"overallCompleted\":37},{\"ts\":1506006000000,\"buyingPrice\":66655609,\"buyingCompleted\":25,\"sellingPrice\":66656349,\"sellingCompleted\":18,\"overallPrice\":66655919,\"overallCompleted\":43},{\"ts\":1506009600000,\"buyingPrice\":66624511,\"buyingCompleted\":16,\"sellingPrice\":66590403,\"sellingCompleted\":13,\"overallPrice\":66609221,\"overallCompleted\":29},{\"ts\":1506013200000,\"buyingPrice\":66587012,\"buyingCompleted\":17,\"sellingPrice\":66566303,\"sellingCompleted\":13,\"overallPrice\":66578038,\"overallCompleted\":30},{\"ts\":1506016800000,\"buyingPrice\":66619350,\"buyingCompleted\":20,\"sellingPrice\":66626082,\"sellingCompleted\":23,\"overallPrice\":66622951,\"overallCompleted\":43},{\"ts\":1506020400000,\"buyingPrice\":66594445,\"buyingCompleted\":19,\"sellingPrice\":66597250,\"sellingCompleted\":13,\"overallPrice\":66595585,\"overallCompleted\":32},{\"ts\":1506024000000,\"buyingPrice\":66581352,\"buyingCompleted\":28,\"sellingPrice\":66572684,\"sellingCompleted\":19,\"overallPrice\":66577848,\"overallCompleted\":47},{\"ts\":1506027600000,\"buyingPrice\":66615549,\"buyingCompleted\":21,\"sellingPrice\":66584286,\"sellingCompleted\":26,\"overallPrice\":66598255,\"overallCompleted\":47},{\"ts\":1506031200000,\"buyingPrice\":66570408,\"buyingCompleted\":33,\"sellingPrice\":66554182,\"sellingCompleted\":22,\"overallPrice\":66563918,\"overallCompleted\":55},{\"ts\":1506034800000,\"buyingPrice\":66582854,\"buyingCompleted\":21,\"sellingPrice\":66567977,\"sellingCompleted\":19,\"overallPrice\":66575787,\"overallCompleted\":40},{\"ts\":1506038400000,\"buyingPrice\":66523721,\"buyingCompleted\":27,\"sellingPrice\":66484616,\"sellingCompleted\":24,\"overallPrice\":66505319,\"overallCompleted\":51},{\"ts\":1506042000000,\"buyingPrice\":66504895,\"buyingCompleted\":23,\"sellingPrice\":66447012,\"sellingCompleted\":25,\"overallPrice\":66474748,\"overallCompleted\":48},{\"ts\":1506045600000,\"buyingPrice\":66538601,\"buyingCompleted\":25,\"sellingPrice\":66510720,\"sellingCompleted\":18,\"overallPrice\":66526930,\"overallCompleted\":43},{\"ts\":1506049200000,\"buyingPrice\":66538909,\"buyingCompleted\":18,\"sellingPrice\":66502608,\"sellingCompleted\":17,\"overallPrice\":66521277,\"overallCompleted\":35},{\"ts\":1506052800000,\"buyingPrice\":66524335,\"buyingCompleted\":23,\"sellingPrice\":66511949,\"sellingCompleted\":24,\"overallPrice\":66518010,\"overallCompleted\":47},{\"ts\":1506056400000,\"buyingPrice\":66464374,\"buyingCompleted\":32,\"sellingPrice\":66455408,\"sellingCompleted\":29,\"overallPrice\":66460112,\"overallCompleted\":61},{\"ts\":1506060000000,\"buyingPrice\":66483783,\"buyingCompleted\":19,\"sellingPrice\":66495745,\"sellingCompleted\":33,\"overallPrice\":66491374,\"overallCompleted\":52},{\"ts\":1506063600000,\"buyingPrice\":66520155,\"buyingCompleted\":21,\"sellingPrice\":66517774,\"sellingCompleted\":22,\"overallPrice\":66518937,\"overallCompleted\":43},{\"ts\":1506067200000,\"buyingPrice\":66482590,\"buyingCompleted\":9,\"sellingPrice\":66443527,\"sellingCompleted\":11,\"overallPrice\":66461106,\"overallCompleted\":20},{\"ts\":1506070800000,\"buyingPrice\":66484890,\"buyingCompleted\":18,\"sellingPrice\":66461708,\"sellingCompleted\":10,\"overallPrice\":66476611,\"overallCompleted\":28},{\"ts\":1506074400000,\"buyingPrice\":66547890,\"buyingCompleted\":9,\"sellingPrice\":66473436,\"sellingCompleted\":15,\"overallPrice\":66501356,\"overallCompleted\":24},{\"ts\":1506078000000,\"buyingPrice\":66495595,\"buyingCompleted\":16,\"sellingPrice\":66426685,\"sellingCompleted\":13,\"overallPrice\":66464705,\"overallCompleted\":29},{\"ts\":1506081600000,\"buyingPrice\":66532618,\"buyingCompleted\":10,\"sellingPrice\":66495024,\"sellingCompleted\":17,\"overallPrice\":66508948,\"overallCompleted\":27},{\"ts\":1506085200000,\"buyingPrice\":66505088,\"buyingCompleted\":25,\"sellingPrice\":66526120,\"sellingCompleted\":26,\"overallPrice\":66515810,\"overallCompleted\":51},{\"ts\":1506088800000,\"buyingPrice\":66542426,\"buyingCompleted\":22,\"sellingPrice\":66525025,\"sellingCompleted\":17,\"overallPrice\":66534841,\"overallCompleted\":39},{\"ts\":1506092400000,\"buyingPrice\":66494138,\"buyingCompleted\":12,\"sellingPrice\":66476505,\"sellingCompleted\":8,\"overallPrice\":66487085,\"overallCompleted\":20},{\"ts\":1506096000000,\"buyingPrice\":66500474,\"buyingCompleted\":15,\"sellingPrice\":66494646,\"sellingCompleted\":15,\"overallPrice\":66497560,\"overallCompleted\":30},{\"ts\":1506099600000,\"buyingPrice\":66457854,\"buyingCompleted\":21,\"sellingPrice\":66457903,\"sellingCompleted\":29,\"overallPrice\":66457883,\"overallCompleted\":50},{\"ts\":1506103200000,\"buyingPrice\":66502500,\"buyingCompleted\":4,\"sellingPrice\":66454837,\"sellingCompleted\":6,\"overallPrice\":66473902,\"overallCompleted\":10}]";
  16.  
  17. public static void main(String[] args) {
  18.  
  19. HashMap<Long, double[]> dataHash = readData(data);
  20.  
  21. Ensemble e = new Ensemble(dataHash);
  22.  
  23. ArrayList<Long> times = new ArrayList<>(dataHash.keySet());
  24.  
  25. Collections.sort(times);
  26.  
  27. DecimalFormat f = new DecimalFormat("#,###,###,##0.000");
  28.  
  29. long now = System.currentTimeMillis();
  30.  
  31. for (long i = 0; i < 7200000; i += 300000) {
  32. System.out.println("Buy price @ " + new Date(now + i) + ": " + f.format(e.getBP(now + i)));
  33. }
  34. }
  35.  
  36. /**
  37. * Single variable prediction forest expressing all variables as a function of only time.
  38. */ static class Ensemble {
  39.  
  40. HashMap<Long, double[]> dataHash;
  41.  
  42. RandomForest BPF, SPF;
  43.  
  44. public Ensemble(HashMap<Long, double[]> data) {
  45.  
  46. double[][] BPX = new double[times.size()][]; double[] BPY = new double[times.size()];
  47. double[][] SPX = new double[times.size()][]; double[] SPY = new double[times.size()];
  48.  
  49. for (int i = 0; i < times.size(); i++) {
  50.  
  51. long time = times.get(i);
  52.  
  53. // info = {BP, SP, BC, SC}
  54.  
  55. double[] info = dataHash.get(time);
  56.  
  57. BPX[i] = new double[] {time};
  58. BPY[i] = info[0];
  59.  
  60. SPX[i] = new double[] {time};
  61. SPY[i] = info[1];
  62. }
  63.  
  64. BPF = new RandomForest(BPX, BPY, nTrees, nNodes, sNodes, 1);
  65. SPF = new RandomForest(SPX, SPY, nTrees, nNodes, sNodes, 1);
  66. }
  67.  
  68. public double getBP(long time) {
  69.  
  70. return BPF.predict(new double[] {time});
  71. }
  72.  
  73. public double getSP(long time) {
  74.  
  75. return SPF.predict(new double[] {time});
  76. }
  77. }
  78.  
  79. static HashMap<Long, double[]> readData(String data) {
  80.  
  81. HashMap<Long, double[]> dataHash = new HashMap<>();
  82.  
  83. String[] elements = data.split("\\{");
  84.  
  85. // ADD DATA TO STORAGE
  86.  
  87. for (String element : elements) {
  88.  
  89. String[] pieces = element.split(":");
  90.  
  91. Long time = null;
  92. Integer BP = null, SP = null, BC = null, SC = null;
  93.  
  94. for (int i = 0; i < pieces.length; i++) {
  95.  
  96. if (time == null && pieces[i].contains("\"ts\"")) {
  97. time = Long.parseLong(pieces[i + 1].split(",")[0].replaceAll("[^\\d.]", "").trim());
  98. } else if (BP == null && pieces[i].contains("\"buyingPrice\"")) {
  99. BP = Integer.parseInt(pieces[i + 1].split(",")[0].replaceAll("[^\\d.]", "").trim());
  100. } else if (SP == null && pieces[i].contains("\"sellingPrice\"")) {
  101. SP = Integer.parseInt(pieces[i + 1].split(",")[0].replaceAll("[^\\d.]", "").trim());
  102. } else if (BC == null && pieces[i].contains("\"buyingCompleted\"")) {
  103. BC = Integer.parseInt(pieces[i + 1].split(",")[0].replaceAll("[^\\d.]", "").trim());
  104. } else if (SC == null && pieces[i].contains("\"sellingCompleted\"")) {
  105. SC = Integer.parseInt(pieces[i + 1].split(",")[0].replaceAll("[^\\d.]", "").trim());
  106. }
  107.  
  108. if (time != null && BP != null && SP != null && BC != null && SC != null) {
  109.  
  110. if (System.currentTimeMillis() - time > 0) {
  111.  
  112. dataHash.put(time, new double[] {BP, SP, BC, SC});
  113. }
  114.  
  115. break;
  116. }
  117. }
  118. }
  119.  
  120. return dataHash;
  121. }
  122. }
Add Comment
Please, Sign In to add comment