MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Oil and gold price chart, for your interest

  • To: mathgroup at smc.vnet.net
  • Subject: [mg103270] Re: Oil and gold price chart, for your interest
  • From: Armand Tamzarian <mike.honeychurch at gmail.com>
  • Date: Fri, 11 Sep 2009 19:58:50 -0400 (EDT)
  • References: <h8d502$nb$1@smc.vnet.net>

On Sep 11, 4:24 am, Chris Degnen <deg... at cwgsy.net> wrote:
> spotPrices =
>   Import["http://www.eia.doe.gov/emeu/international/Crude1.xls";,
>    "XLS"];
> spotPriceWTI = {#[[1, 1 ;; 3]], #[[4]]} & /@
>    DeleteCases[
>     spotPrices[[1, 2 ;;]], {_, _, _, "NA"} | {_, _, _, ""}];
> goldPrices =
>   Import["http://www.lbma.org.uk/?area=stats&page=gold/2009dailygol=
d",
>     "HTML"];
> goldPrices2 = StringSplit[goldPrices, "\n"];
> Take[goldPrices2, 9];
> goldPrices3 = Drop[goldPrices2, 8];
> Take[goldPrices2, -21];
> goldPrices4 = Drop[goldPrices3, -20];
> goldPrices5 =
>   DeleteCases[If[StringLength[#] > 10, #, Null] & /@ goldPrices4,
>    Null];
> goldPrices6 = {StringTake[#, 9], StringTake[#, {11, 16}]} & /@
>    goldPrices5;
> goldPrices7 = {DateList[#[[1]]], ToExpression[#[[2]]]/10} & /@
>    goldPrices6;
> pricesPlot =
>   DateListPlot[{goldPrices7,
>     Take[spotPriceWTI, 7 - Length[goldPrices7]]},
>    PlotLabel -> Style["\n2009 Oil and Gold Prices ($)", Bold],
>    Joined -> True, PlotRange -> {Automatic, {0, 110}},
>    FrameTicks -> {{{{0, "0"}, {20, "20"}, {40, "40"}, {60, "60"}, {80=
,
>          "80"}, {100, "100"}},
>       {{0, "0"}, {20, "200"}, {40, "400"}, {60, "600"}, {80,
>         "800"}, {100, "1000"}}}, Automatic}];
> Show[pricesPlot]

This is easier ( to read at least):

spotPrices = First@Import["http://www.eia.doe.gov/emeu/international/
Crude1.xls","XLS"];

spotBrent = Cases[spotPrices[[All, {1, 3}]], {_List, x_?NumericQ}];
spotWTI = Cases[spotPrices[[All, {1, 4}]], {_List, x_?NumericQ}];

goldPrices = Import["http://www.lbma.org.uk/?area=stats&page=gold/
2009dailygold","Data"];

goldPrices = Cases[goldPrices, {x_String, y__?NumericQ} :> {DateList
[x], y}, \[Infinity]];

>From here I don't exactly know how you want to make your plot (perhaps
scale the gold price?) or which price to choose but this is a simple
plot:

DateListPlot[{spotPriceWTI, goldPrices[[All, {1, 2}]]}, Joined ->
True, PlotRange -> All]

------

If you wanted to only choose days in which you have data for both WTI
and gold you can use Intersection with a SameTest to create a subset
of the WTI data (or of course use Part or Take and make the choice
manually). General, but slow, case:

WTIsubset1=Quiet@Intersection[spotPriceWTI, goldPrices[[All, 1]],
SameTest -> (#1[[1]] == #2[[{1, 2, 3}]] &)]

Note that the {1,2,3} is necessary because the length of the date
lists differ for the oil and gold.

However if you only want 2009 data, which you would in this case:

WTIsubset2=Cases[spotPriceWTI, {{2009, __}, __}]

Ideally you'd want to have a two axis plot here but this has always
been problematic and breaks whenever I try to implement it with
DateListPlot. Some readers may have a working DateListPlot two axis
plot solution (?)

Mike


  • Prev by Date: Re: Re: how to get the longest ordered sub sequence of a
  • Next by Date: Re: Credit card balance transfer fee problem
  • Previous by thread: Re: Oil and gold price chart, for your interest
  • Next by thread: Re: Oil and gold price chart, for your interest