Re: Oil and gold price chart, for your interest
- To: mathgroup at smc.vnet.net
- Subject: [mg103272] Re: Oil and gold price chart, for your interest
- From: Chris Degnen <degnen at cwgsy.net>
- Date: Sat, 12 Sep 2009 07:25:47 -0400 (EDT)
- References: <h8eo55$opn$1@smc.vnet.net>
On 12 Sep, 00:57, "w... at wavebounce.com" <w... at wavebounce.com> wrote: > I get errors: > DateList::str: String GOLD A.M. cannot be interpreted as a date in format Automatic Yes, version 7 seems to parse the new lines differently in StringSplit [goldPrices, "\n"]. Here's a second version. spotPrices = Import["http://www.eia.doe.gov/emeu/international/Crude1.xls", "XLS"]; spotPriceWTI = {#[[1, 1 ;; 3]], #[[4]]} & /@ DeleteCases[spotPrices[[1, 2 ;;]], {_, _, _, "NA"} | {_, _, _, ""}]; If[$VersionNumber == 6, d1 = d2 = 0, d1 = 2; d2 = 1]; formatGoldPrices[] := Module[{}, goldPrices2 = StringSplit[goldPrices, "\n"]; goldPrices3 = Drop[goldPrices2, d1 + 8]; goldPrices4 = Drop[goldPrices3, d2 - t]; goldPrices5 = DeleteCases[If[StringLength[#] > 10, #, Null] & /@ goldPrices4, Null]; goldPrices6 = {StringTake[#, 9], StringTake[#, {11, 16}]} & /@ goldPrices5; goldPrices7 = {DateList[#[[1]]], ToExpression[#[[2]]]/10} & /@ goldPrices6]; goldPrices = Import["http://www.lbma.org.uk/?area=stats&page=gold/2007dailygold", "HTML"]; t = 20; goldPrices2007 = formatGoldPrices[]; goldPrices = Import["http://www.lbma.org.uk/?area=stats&page=gold/2008dailygold", "HTML"]; t = 19; goldPrices2008 = formatGoldPrices[]; goldPrices = Import["http://www.lbma.org.uk/?area=stats&page=gold/2009dailygold", "HTML"]; t = 20; goldPrices2009 = formatGoldPrices[]; goldPrices8 = Join[goldPrices2007, goldPrices2008, goldPrices2009]; pricesPlot = DateListPlot[{goldPrices8, Take[spotPriceWTI, 12 - Length[goldPrices8]]}, ImageSize -> 700, PlotLabel -> Style["Oil and Gold Prices ($)", Bold], Joined -> True, PlotRange -> {Automatic, {0, 150}}, FrameTicks -> {{{{0, "0"}, {20, "20"}, {40, "40"}, {60, "60"}, {80, "80"}, {100, "100"}, {120, "120"}, {140, "140"}}, {{0, "0"}, {20, "200"}, {40, "400"}, {60, "600"}, {80, "800"}, {100, "1000"}, {120, "1200"}, {140, "1400"}}}, Automatic}]; Show[pricesPlot]