satrapade / pairs

1 stars 1 forks source link

multiple latex to pdf using tikz #29

Open nassuphis opened 6 years ago

nassuphis commented 6 years ago

we need to create a large number of icons representing individual pairs/shares this is best done using a single .Rnw file which creates each icon using the tikz library and then outputs the reulting icon per pair to the appropriate file name

nassuphis commented 6 years ago
make_external_latex<-function(
  latex="testing123",
  filename=NULL
)paste0(
  if(!is.null(filename)){paste0("\\tikzsetnextfilename{",filename,"}"," ")}else{""},
  "\\tikz{\\path (0,0) node[inner sep=0,outer sep=0]{",
  latex,
  "};}"
)
nassuphis commented 6 years ago

for pair icons, we have a function that paints the icon ofr a pair using tikz

pair_icon<-function(
  pair,
  pair_exposure,
  pair_days,
  pair_pnl,
  pair_long_pnl,
  pair_short_pnl,
  drop_one_pair_pnl,
  local_pnl
){
  icon_items<-c(
    paste0("\\multicolumn{1}{@{}c@{}}{",pair_with_pm_color(pair=pair),"}"),
    paste0("\\multicolumn{1}{@{}c@{}}{",pair_price_action(pair=pair,pair_pnl=pair_pnl,w=21,height=2,width = 30,units="mm"),"}"),
    paste0("\\multicolumn{1}{@{}c@{}}{",pair_technicals(
      pair=pair,
      w=365,
      pair_exposure=pair_exposure,
      pair_days=pair_days,
      pair_long_pnl=pair_long_pnl,
      pair_short_pnl=pair_short_pnl,
      drop_one_pair_pnl=drop_one_pair_pnl,
      local_pnl=local_pnl
    ),"}"),
    pair_leg(pair=pair,pair_exposure=pair_exposure,direction=(1),max_char=12),
    pair_leg(pair=pair,pair_exposure=pair_exposure,direction=(-1),max_char=12)
  )
  tbl(x=icon_items,sep=" \\\\ \n",align="@{}p{3.0cm}@{}")
}
nassuphis commented 6 years ago

and we loop over pair icons like this:

latex_icons<-mapply(pair_icon,pair=pairs,MoreArgs=list(
  pair_exposure=pair_exposure,
  pair_days=pair_days,
  pair_pnl=pair_local_pnl,
  pair_long_pnl=pair_long_pnl,
  pair_short_pnl=pair_short_pnl,
  drop_one_pair_pnl=drop_one_pair_pnl,
  local_pnl=local_pnl
),SIMPLIFY = FALSE)

append2log("create_pair_icons.Rnw : create external latex commands")
external_latex_icons<-mapply(
  function(latex,file){
    make_external_latex(latex=latex,filename=file)
  },
  latex=latex_icons,
  #file=paste0("N:/Depts/Share/UK Alpha Team/Analytics/pair_icons/",pairs),
  file=paste0(pairs),
  SIMPLIFY=TRUE
)
nassuphis commented 6 years ago

and finally, we put the latex generated above into the doc:

\Sexpr{paste(external_latex_icons,collapse="\n")}
nassuphis commented 6 years ago

the output looks like this:

for example, pair ABC1

\tikzsetnextfilename{ABC1} \tikz{\path (0,0) node[inner sep=0,outer sep=0]{\begin{tabular}{@{}p{3.0cm}@{}} \multicolumn{1}{@{}c@{}}{\cellcolor{ABC!33}ABC1} \\ 
\multicolumn{1}{@{}c@{}}{\tikz{
\path 
( 0.0mm,0mm)node[shape=regular polygon, regular polygon sides=3,rotate=180,fill=red,inner sep=0.25mm,minimum height=2mm]{}
  ( 1.5mm,0mm)node[shape=regular polygon, regular polygon sides=3,rotate=180,fill=red,inner sep=0.25mm,minimum height=2mm]{}
  ( 3.0mm,0mm)node[shape=cross out,draw=black,line width=0.125mm,inner sep=0.25mm,minimum height=1mm]{}
  ( 4.5mm,0mm)node[shape=cross out,draw=black,line width=0.125mm,inner sep=0.25mm,minimum height=1mm]{}
  ( 6.0mm,0mm)node[shape=regular polygon, regular polygon sides=3,rotate=180,fill=red,inner sep=0.25mm,minimum height=2mm]{}
  ( 7.5mm,0mm)node[shape=regular polygon, regular polygon sides=3,rotate=180,fill=red,inner sep=0.25mm,minimum height=2mm]{}
  ( 9.0mm,0mm)node[shape=regular polygon, regular polygon sides=3,rotate=180,fill=red,inner sep=0.25mm,minimum height=2mm]{}
  (10.5mm,0mm)node[shape=regular polygon, regular polygon sides=3,fill=green,inner sep=0.25mm,minimum height=2mm]{}
  (12.0mm,0mm)node[shape=regular polygon, regular polygon sides=3,fill=green,inner sep=0.25mm,minimum height=2mm]{}
  (13.5mm,0mm)node[shape=cross out,draw=black,line width=0.125mm,inner sep=0.25mm,minimum height=1mm]{}
  (15.0mm,0mm)node[shape=cross out,draw=black,line width=0.125mm,inner sep=0.25mm,minimum height=1mm]{}
  (16.5mm,0mm)node[shape=regular polygon, regular polygon sides=3,fill=green,inner sep=0.25mm,minimum height=2mm]{}
  (18.0mm,0mm)node[shape=regular polygon, regular polygon sides=3,fill=green,inner sep=0.25mm,minimum height=2mm]{}
  (19.5mm,0mm)node[shape=regular polygon, regular polygon sides=3,rotate=180,fill=red,inner sep=0.25mm,minimum height=2mm]{}
  (21.0mm,0mm)node[shape=regular polygon, regular polygon sides=3,fill=green,inner sep=0.25mm,minimum height=2mm]{}
  (22.5mm,0mm)node[shape=regular polygon, regular polygon sides=3,rotate=180,fill=red,inner sep=0.25mm,minimum height=2mm]{}
  (24.0mm,0mm)node[shape=cross out,draw=black,line width=0.125mm,inner sep=0.25mm,minimum height=1mm]{}
  (25.5mm,0mm)node[shape=cross out,draw=black,line width=0.125mm,inner sep=0.25mm,minimum height=1mm]{}
  (27.0mm,0mm)node[shape=regular polygon, regular polygon sides=3,rotate=180,fill=red,inner sep=0.25mm,minimum height=2mm]{}
  (28.5mm,0mm)node[shape=regular polygon, regular polygon sides=3,rotate=180,fill=red,inner sep=0.25mm,minimum height=2mm]{}
  (30.0mm,0mm)node[shape=cross out,draw=black,line width=0.125mm,inner sep=0.25mm,minimum height=1mm]{}
 ;}} \\ 
\multicolumn{1}{@{}c@{}}{\begin{tabular}{@{}l@{\hskip 1pt}l@{\hskip 1pt}l@{}}v0.4 & r3.5 & g164\\{\small\sfrac{RSI}{3m}:56} & {\small\sfrac{RSI}{1m}:55} & {\small\sfrac{RSI}{2w}:53} \\ {\small12m:84} & {\small6m:70} & {\small1m:73} \\ \fbox{\tikz{\fill[green] (8mm,2mm) circle(0.5mm);\fill[red] (0mm,0mm) circle(0.5mm);\draw[line width=0.2mm, inner sep=0pt, outer sep=0pt] (0.0000mm,0.0000mm)--(0.4211mm,0.0469mm)--(0.8421mm,0.1027mm)--(1.2632mm,0.1755mm)--(1.6842mm,0.2334mm)--(2.1053mm,0.3205mm)--(2.5263mm,0.4554mm)--(2.9474mm,0.6254mm)--(3.3684mm,0.8074mm)--(3.7895mm,0.9406mm)--(4.2105mm,1.1091mm)--(4.6316mm,1.2278mm)--(5.0526mm,1.3938mm)--(5.4737mm,1.5400mm)--(5.8947mm,1.6818mm)--(6.3158mm,1.8039mm)--(6.7368mm,1.9513mm)--(7.1579mm,1.9497mm)--(7.5789mm,1.9830mm)--(8.0000mm,2.0000mm);}}&\fbox{\tikz{\fill[green] (5.8947mm,2mm) circle(0.5mm);\fill[red] (0mm,0mm) circle(0.5mm);\draw[line width=0.2mm, inner sep=0pt, outer sep=0pt] (0.0000mm,0.0000mm)--(0.4211mm,0.1384mm)--(0.8421mm,0.3157mm)--(1.2632mm,0.4921mm)--(1.6842mm,0.7207mm)--(2.1053mm,1.0270mm)--(2.5263mm,1.2441mm)--(2.9474mm,1.3247mm)--(3.3684mm,1.4566mm)--(3.7895mm,1.5056mm)--(4.2105mm,1.4962mm)--(4.6316mm,1.5259mm)--(5.0526mm,1.7921mm)--(5.4737mm,1.9330mm)--(5.8947mm,2.0000mm)--(6.3158mm,1.9547mm)--(6.7368mm,1.9089mm)--(7.1579mm,1.7514mm)--(7.5789mm,1.6204mm)--(8.0000mm,1.6426mm);}}&\fbox{\tikz{\fill[green] (7.5789mm,2mm) circle(0.5mm);\fill[red] (3.7895mm,0mm) circle(0.5mm);\draw[line width=0.2mm, inner sep=0pt, outer sep=0pt] (0.0000mm,1.1246mm)--(0.4211mm,1.3526mm)--(0.8421mm,1.3573mm)--(1.2632mm,1.2882mm)--(1.6842mm,1.0196mm)--(2.1053mm,0.8503mm)--(2.5263mm,0.6810mm)--(2.9474mm,0.4571mm)--(3.3684mm,0.0453mm)--(3.7895mm,0.0000mm)--(4.2105mm,0.1255mm)--(4.6316mm,0.2511mm)--(5.0526mm,0.5246mm)--(5.4737mm,0.8688mm)--(5.8947mm,1.2140mm)--(6.3158mm,1.5142mm)--(6.7368mm,1.7688mm)--(7.1579mm,1.8961mm)--(7.5789mm,2.0000mm)--(8.0000mm,1.8610mm);}}\\\end{tabular}} \\ 
{\small  DSM } \\ 
{\small  KYG-SX4E }\\ \end{tabular}};}
nassuphis commented 6 years ago

and another one:

\tikzsetnextfilename{ABC11} \tikz{\path (0,0) node[inner sep=0,outer sep=0]{\begin{tabular}{@{}p{3.0cm}@{}} \multicolumn{1}{@{}c@{}}{\cellcolor{ABC!33}ABC11} \\ 
\multicolumn{1}{@{}c@{}}{\tikz{
\path 
( 0.0mm,0mm)node[shape=regular polygon, regular polygon sides=3,fill=green,inner sep=0.25mm,minimum height=2mm]{}
  ( 1.5mm,0mm)node[shape=regular polygon, regular polygon sides=3,fill=green,inner sep=0.25mm,minimum height=2mm]{}
  ( 3.0mm,0mm)node[shape=cross out,draw=black,line width=0.125mm,inner sep=0.25mm,minimum height=1mm]{}
  ( 4.5mm,0mm)node[shape=cross out,draw=black,line width=0.125mm,inner sep=0.25mm,minimum height=1mm]{}
  ( 6.0mm,0mm)node[shape=regular polygon, regular polygon sides=3,fill=green,inner sep=0.25mm,minimum height=2mm]{}
  ( 7.5mm,0mm)node[shape=regular polygon, regular polygon sides=3,rotate=180,fill=red,inner sep=0.25mm,minimum height=2mm]{}
  ( 9.0mm,0mm)node[shape=regular polygon, regular polygon sides=3,fill=green,inner sep=0.25mm,minimum height=2mm]{}
  (10.5mm,0mm)node[shape=regular polygon, regular polygon sides=3,fill=green,inner sep=0.25mm,minimum height=2mm]{}
  (12.0mm,0mm)node[shape=regular polygon, regular polygon sides=3,rotate=180,fill=red,inner sep=0.25mm,minimum height=2mm]{}
  (13.5mm,0mm)node[shape=cross out,draw=black,line width=0.125mm,inner sep=0.25mm,minimum height=1mm]{}
  (15.0mm,0mm)node[shape=cross out,draw=black,line width=0.125mm,inner sep=0.25mm,minimum height=1mm]{}
  (16.5mm,0mm)node[shape=regular polygon, regular polygon sides=3,fill=green,inner sep=0.25mm,minimum height=2mm]{}
  (18.0mm,0mm)node[shape=regular polygon, regular polygon sides=3,fill=green,inner sep=0.25mm,minimum height=2mm]{}
  (19.5mm,0mm)node[shape=regular polygon, regular polygon sides=3,rotate=180,fill=red,inner sep=0.25mm,minimum height=2mm]{}
  (21.0mm,0mm)node[shape=regular polygon, regular polygon sides=3,rotate=180,fill=red,inner sep=0.25mm,minimum height=2mm]{}
  (22.5mm,0mm)node[shape=regular polygon, regular polygon sides=3,rotate=180,fill=red,inner sep=0.25mm,minimum height=2mm]{}
  (24.0mm,0mm)node[shape=cross out,draw=black,line width=0.125mm,inner sep=0.25mm,minimum height=1mm]{}
  (25.5mm,0mm)node[shape=cross out,draw=black,line width=0.125mm,inner sep=0.25mm,minimum height=1mm]{}
  (27.0mm,0mm)node[shape=regular polygon, regular polygon sides=3,fill=green,inner sep=0.25mm,minimum height=2mm]{}
  (28.5mm,0mm)node[shape=regular polygon, regular polygon sides=3,fill=green,inner sep=0.25mm,minimum height=2mm]{}
  (30.0mm,0mm)node[shape=cross out,draw=black,line width=0.125mm,inner sep=0.25mm,minimum height=1mm]{}
 ;}} \\ 
\multicolumn{1}{@{}c@{}}{\begin{tabular}{@{}l@{\hskip 1pt}l@{\hskip 1pt}l@{}}v0.2 & r(-13) & g153\\{\small\sfrac{RSI}{3m}:53} & {\small\sfrac{RSI}{1m}:55} & {\small\sfrac{RSI}{2w}:63} \\ {\small12m:98} & {\small6m:96} & {\small1m:93} \\ \fbox{\tikz{\fill[green] (5.4737mm,2mm) circle(0.5mm);\fill[red] (0mm,0mm) circle(0.5mm);\draw[line width=0.2mm, inner sep=0pt, outer sep=0pt] (0.0000mm,0.0000mm)--(0.4211mm,0.1280mm)--(0.8421mm,0.1769mm)--(1.2632mm,0.2794mm)--(1.6842mm,0.3225mm)--(2.1053mm,0.4585mm)--(2.5263mm,0.6763mm)--(2.9474mm,1.0189mm)--(3.3684mm,1.3049mm)--(3.7895mm,1.6096mm)--(4.2105mm,1.9009mm)--(4.6316mm,1.9660mm)--(5.0526mm,1.9892mm)--(5.4737mm,2.0000mm)--(5.8947mm,1.8859mm)--(6.3158mm,1.6279mm)--(6.7368mm,1.4525mm)--(7.1579mm,1.4519mm)--(7.5789mm,1.5111mm)--(8.0000mm,1.7738mm);}}&\fbox{\tikz{\fill[green] (8mm,2mm) circle(0.5mm);\fill[red] (5.4737mm,0mm) circle(0.5mm);\draw[line width=0.2mm, inner sep=0pt, outer sep=0pt] (0.0000mm,1.5262mm)--(0.4211mm,1.6209mm)--(0.8421mm,1.5976mm)--(1.2632mm,1.5056mm)--(1.6842mm,1.3864mm)--(2.1053mm,1.1701mm)--(2.5263mm,1.0771mm)--(2.9474mm,1.1686mm)--(3.3684mm,1.2317mm)--(3.7895mm,1.0853mm)--(4.2105mm,0.8643mm)--(4.6316mm,0.6393mm)--(5.0526mm,0.2525mm)--(5.4737mm,0.0000mm)--(5.8947mm,0.0069mm)--(6.3158mm,0.3880mm)--(6.7368mm,0.7776mm)--(7.1579mm,1.1803mm)--(7.5789mm,1.6686mm)--(8.0000mm,2.0000mm);}}&\fbox{\tikz{\fill[green] (5.8947mm,2mm) circle(0.5mm);\fill[red] (2.5263mm,0mm) circle(0.5mm);\draw[line width=0.2mm, inner sep=0pt, outer sep=0pt] (0.0000mm,0.6608mm)--(0.4211mm,0.6367mm)--(0.8421mm,0.5624mm)--(1.2632mm,0.2812mm)--(1.6842mm,0.1040mm)--(2.1053mm,0.0520mm)--(2.5263mm,0.0000mm)--(2.9474mm,0.1133mm)--(3.3684mm,0.5519mm)--(3.7895mm,0.8398mm)--(4.2105mm,1.0640mm)--(4.6316mm,1.2882mm)--(5.0526mm,1.6259mm)--(5.4737mm,1.8365mm)--(5.8947mm,2.0000mm)--(6.3158mm,1.9240mm)--(6.7368mm,1.6468mm)--(7.1579mm,1.5082mm)--(7.5789mm,1.4220mm)--(8.0000mm,1.3894mm);}}\\\end{tabular}} \\ 
{\small  LINU } \\ 
{\small  AI-DAX }\\ \end{tabular}};}
nassuphis commented 6 years ago

image

nassuphis commented 6 years ago

the ionkey file ICONKEY.pdf

nassuphis commented 6 years ago

amd the "create pair icons" file: create_pair_icons.pdf

nassuphis commented 6 years ago

images.csv contains a mapping of pair names to the appropriate file: