2015-12-16 54 views
1

我想加载并读取股票历史数据到netlogo中,我发现how to read a .CSV file with netlogo是非常有帮助的。如何将CSV文件中的股票数据读入netlogo?

然而,要实现我需要什么,我还需要进入的fileList每个元素列表(见上面的链接),并提取元素列表中的每个元素,并将它们存储到不同的表像datesopenPriceshighPrices等等。

任何人都可以告诉我如何实现它的方式?或者指向一些代码示例也可以非常有帮助。我刚开始学习netlogo,所以有很多要跟上。

非常感谢!

股票历史数据看起来像这样

2015年12月15日,12,12.9,11.99,12.5,10000

2015年12月16日,12.1,13.9,11.99,12.8,11000

globals[eachLine dates openPrices highPrices lowPrices closePrices volumes] 

to openFile 
    file-open "jqr.txt" 
    set dates [] 
    set openPrices [] 
    set highPrices [] 
    set lowPrices [] 
    set closePrices [] 
    set volumes [] 

    set fileList [] 

    while [not file-at-end?] [ 
    set csv file-read-line 
    set csv word csv "," ; add comma for loop termination 

    let mylist [] ; list of values 
    while [not empty? csv] 
    [ 
     let $x position "," csv 
     let $item substring csv 0 $x ; extract item 
     carefully [set $item read-from-string $item][] ; convert if number 
     set mylist lput $item mylist ; append to list 
     set csv substring csv ($x + 1) length csv ; remove item and comma 
    ] 
    set fileList lput mylist fileList 
    ] 

    ;; ?????? 
    foreach fileList 




    show fileList 
    file-close 
end 

回答