|
NetLogo /
TableMake a table (key:price value: cumulative_volume), then add volume to key on each tick To exhibit table as a graph, find the low and highest key to use for x coord of graph, then convert table to a list and plotxy each item in list foreach price-vol-list [plotxy item 0 ? item 1 ?] ;;sequential-specifics.nls globals [logfile ;; assume HLOCV order data-time data-high data-low data-open data-close data-vol price-vol-table price-spread vol-per-unit] to specifics-setup ; main nlogo has clear-all, which clears plots ; clear-plots set logfile "logfile.txt" let log-entry word "\r -- New Session -- " date-and-time if print-to-logfile? [ print-to-file logfile log-entry print-to-file logfile logfile print-to-file logfile data-source ] output-print log-entry output-print logfile output-print data-source ;; Add you setup requirements here ; create the table (key:price, value:volume) set price-vol-table table:make ; high minus low, plus 1 gives the range to fill ; initial calculation (same as in specifics-go ;set price-spread (4 * 100 * (data-high - data-low)) + 1 ;set vol-per-unit precision ( data-vol / price-spread ) 0 clear-plots end to specifics-go ;; PRINTING ;; to logfile: if print-to-logfile? [ print-to-file logfile (word "data-close " data-close " data-vol " data-vol) ] ;; To interface output: if print-to-output? [ output-print (word "data-one " data-close " data-vol " data-vol ) ] if in-date-range [ set price-spread (4 * 100 * ( data-high - data-low )) + 1 set vol-per-unit precision ( data-vol / price-spread ) 0 ;elminate zeroes, set to as at least 1 if vol-per-unit < 1 [ set vol-per-unit 1] add-vol ] end to specifics-get-next-record ;this will work with any HLOCV csv file (daily, hourly, 5 minute) ;see if this is all the changes needed for date, close vol set data-time item 0 vals-list set data-high item 1 vals-list set data-low item 1 vals-list set data-open item 1 vals-list set data-close item 1 vals-list set data-vol item 2 vals-list end to clear-plots set-current-plot "chart-close" clear-plot set-plot-y-range precision (data-low - 0.0025) 4 precision (data-high + 0.0025) 4 set-current-plot "pv-chart" clear-plot set-plot-x-range precision (data-low - 0.0025) 4 precision (data-high + 0.0025) 4 end to add-vol let pos precision data-low 4; low while [pos <= precision data-high 4] ; high [ifelse table:has-key? price-vol-table pos [ table:put price-vol-table pos table:get price-vol-table pos + vol-per-unit ] [table:put price-vol-table pos vol-per-unit ] set pos precision (pos + 0.0025) 4 ] ; end while ;only show with button ;plotxy-price-vol end to plotxy-price-vol set-current-plot "pv-chart" clear-plot let table-range table:keys price-vol-table let table-low min table-range let table-high max table-range set-plot-x-range table-low - 0.0025 table-high let price-vol-list table:to-list price-vol-table foreach price-vol-list [plotxy item 0 ? item 1 ?] output-print (word "length " table:length price-vol-table " low " table-low " high " table-high ) end ; map [item 1 ?] table:to-list mytable to-report in-date-range let start-date time:create(time-start) let end-date time:create(time-end) let cur-date time:create(data-time) let in-range false if (time:is-after cur-date start-date; put it betwee or time:is-equal cur-date start-date ) ; put it between and (time:is-before cur-date end-date; put it betwee or time:is-equal cur-date end-date) ; put it between [set in-range true] report in-range end |