Created
March 16, 2018 12:08
-
-
Save blippy/0ebbdeab2a020311aa996f7817b5c7eb to your computer and use it in GitHub Desktop.
Portfolio in Mathematica
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env wolframscript | |
(* ::Package:: *) | |
(* ::Input:: *) | |
(*tbl1 = Import[FileNameJoin[{$HomeDirectory , "tmp", "port.tsv"}]];*) | |
(* ::Input:: *) | |
(*(* Some of the types of prices you can ask for *)*) | |
(**) | |
(*(* First, some helper functions *)*) | |
(*Fina[sym_, what_] := EntityValue[Entity["Financial", sym], what];*) | |
(*Fina2[sym_, what_] := Part[Fina[sym, what], 2];*) | |
(**) | |
(*(* And now the real deal ... *)*) | |
(*OpenPrice[sym_] := Fina[sym, "Open"];*) | |
(**) | |
(*(* These can seem a little unreliable: *)*) | |
(*ClosePrice[sym_] := Fina[sym, "Close"];*) | |
(*AskPrice[sym_] := Fina2[sym, "Ask", 2];*) | |
(*LastPrice[sym_] := Fina2[sym, "Last"];*) | |
(* ::Input:: *) | |
(**) | |
(*f[row_] := (r1 =row[[1]]; r2 = row[[2]]; sp = OpenPrice[r1]; {r1,r2, sp, r2*sp});*) | |
(*tover[fn_] := Table[fn[tbl1[[r]]], {r, Length[tbl1]}];*) | |
(*tbl2 = tover[f];*) | |
(*tbl3 = Grid[tbl2, Alignment -> Right]*) | |
(**) | |
(* ::Input:: *) | |
(*port = Total[tbl2[[All, 4]]] *) | |
(*Print[port]*) | |
(* ::Input:: *) | |
(*Now*) | |
(* ::Input:: *) | |
(*EntityProperties["Financial"]*) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment