Attic/trade.scala
changeset 469 48de09728447
parent 35 9fea5f751be4
equal deleted inserted replaced
468:0587ef444547 469:48de09728447
       
     1 // Part 2 about Buy-Low-Sell-High using Yahoo Financial Data
       
     2 //===========================================================
       
     3 
       
     4 
       
     5 // (1) Complete the function that is given a list of floats
       
     6 // and calculuates the indices for when to buy the commodity 
       
     7 // and when to sell
       
     8 
       
     9 def trade_times(xs: List[Double]): (Int, Int) = ...
       
    10 
       
    11 
       
    12 // an example
       
    13 //val prices = List(28.0, 18.0, 20.0, 26.0, 24.0)
       
    14 //assert(trade_times(prices) == (1, 3), "the trade_times test fails")
       
    15 
       
    16 
       
    17 // (2) Complete the ``get webpage'' function that takes a
       
    18 // a stock symbol as argument and queries the Yahoo server
       
    19 // at
       
    20 //      http://ichart.yahoo.com/table.csv?s=<<insert stock symbol>>
       
    21 // 
       
    22 // This servive returns a CSV-list that needs to be separated into
       
    23 // a list of strings.
       
    24 
       
    25 def get_page(symbol: String): List[String] = ...
       
    26 
       
    27 // (3) Complete the function that processes the CSV list
       
    28 // extracting the dates and anjusted close prices. The
       
    29 // prices need to be transformed into Doubles.
       
    30 
       
    31 def process_page(symbol: String): List[(String, Double)] = ...
       
    32 
       
    33 
       
    34 // (4) Complete the query_company function that obtains the
       
    35 // processed CSV-list for a stock symbol. It should return
       
    36 // the dates for when to buy and sell the stocks of that company.
       
    37 
       
    38 def query_company(symbol: String): (String, String) =
       
    39 
       
    40 
       
    41 
       
    42 // some test cases
       
    43 
       
    44 //query_company("GOOG")
       
    45 
       
    46 // some more test cases
       
    47 /*
       
    48 val indices = List("GOOG", "AAPL", "MSFT", "IBM", "FB", "YHOO", "AMZN", "BIDU")
       
    49 
       
    50 for (name <- indices) {
       
    51   val times = query_company(name)
       
    52   println(s"Buy ${name} on ${times._1} and sell on ${times._2}")
       
    53 }
       
    54 */
       
    55 
       
    56