Code Monkey home page Code Monkey logo

Comments (9)

nassuphis avatar nassuphis commented on July 30, 2024
> dim(pair_pnl_matrix)
[1] 731 101
> 

from pairs.

nassuphis avatar nassuphis commented on July 30, 2024
duke_pair_look_vs_outright<-readLines(
  if(off_site){
    "https://raw.githubusercontent.com/satrapade/pairs/master/data/duke_pair_look_vs_outright.csv"
  } else {
    "N:/Depts/Share/UK Alpha Team/Analytics/duke_summary/duke_pair_look_vs_outright.csv"
  }
) %>% paste0(collapse="\n") %>% fread

look_through_pair_exposure<-duke_pair_look_vs_outright[
  TRUE,
  .(
    Exposure=sum(Outright+LookThrough)
  ),
  keyby=c("Pair","SuperSectorIndex")
]

pair_lt_matrix<-NNcast(
  look_through_pair_exposure,
  i_name="Pair",
  j_name="gsub(' Index','',SuperSectorIndex)%>%{ifelse(.=='','Unknown',.)}",
  v_name="Exposure"
)%>%{.[,colnames(.)!="Unknown"]}

from pairs.

nassuphis avatar nassuphis commented on July 30, 2024
> dim(pair_lt_matrix)
[1] 103  19

from pairs.

nassuphis avatar nassuphis commented on July 30, 2024
> setdiff(rownames(pair_lt_matrix),colnames(pair_pnl_matrix))
[1] "MC140" "MC154"

from pairs.

nassuphis avatar nassuphis commented on July 30, 2024

the look-through calculation did not run today

image

from pairs.

nassuphis avatar nassuphis commented on July 30, 2024
> mapply(fetch_index_weights,duke_index_exposure$Ticker)
Error: <SQL> 'SELECT MAX(HistoricalDate) FROM tHistoricalProductHolding WHERE ProductId=NA'
  nanodbc/nanodbc.cpp:1587: 42S22: [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid column name 'NA'. 
 Show Traceback
 
 Rerun with Debug
 Error: <SQL> 'SELECT MAX(HistoricalDate) FROM tHistoricalProductHolding WHERE ProductId=NA'
  nanodbc/nanodbc.cpp:1587: 42S22: [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid column name 'NA'. 
> 

from pairs.

nassuphis avatar nassuphis commented on July 30, 2024
> fetch_index_weights
function(
  equity_index_ticker="UKX Index",
  db=get("db",parent.frame())
){
  
  product_types<-query("SELECT * FROM tProductType",db=db)[,.SD,keyby=Name]
  
  equity_index_products<-query(make_query(
    product_type=product_types["Equity Index",ProductTypeId],
    query_string = "SELECT * FROM tProduct WHERE ProductTypeId=--R{product_type}--"
  ),db=db)[,.SD,keyby=PrimaryDataSourceProductCode]
  
  equity_index_update<-query(make_query(
    product_id=equity_index_products[equity_index_ticker,ProductId],
    query_string = "SELECT MAX(HistoricalDate) FROM tHistoricalProductHolding WHERE ProductId=--R{product_id}--"
  ),db=db)[[1]]
  
  equity_index_weights<-query(make_query(
    product_id=equity_index_products[equity_index_ticker,ProductId],
    update_date=equity_index_update,
    query_string = "
      SELECT 
        tProduct.PrimaryDataSourceProductCode AS IndexTicker,
        tSecurity.Ticker AS Ticker,
        tSecurity.UniqueId AS UniqueId,
        tHistoricalProductHolding.SecurityUnits AS Weight
      FROM tHistoricalProductHolding 
      LEFT JOIN tProduct ON tProduct.ProductId=tHistoricalProductHolding.ProductId
      LEFT JOIN tSecurity ON tSecurity.SecurityId=tHistoricalProductHolding.SecurityId
      WHERE tHistoricalProductHolding.ProductId=--R{product_id}-- 
      AND tHistoricalProductHolding.HistoricalDate='--R{update_date}--'
    "
  ),db=db)
  
  equity_index_weights
  
}
<bytecode: 0x000000002ee42678>

from pairs.

nassuphis avatar nassuphis commented on July 30, 2024
> mapply(
+   function(ndx){
+     cat(ndx,"\n")
+     fetch_index_weights(ndx)
+   },
+   duke_index_exposure$Ticker
+ )
CAC Index 
DAX Index 
F3BANK Index 
F3FINS Index 
Error: <SQL> 'SELECT MAX(HistoricalDate) FROM tHistoricalProductHolding WHERE ProductId=NA'
  nanodbc/nanodbc.cpp:1587: 42S22: [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid column name 'NA'. 
 Show Traceback
 
 Rerun with Debug
 Error: <SQL> 'SELECT MAX(HistoricalDate) FROM tHistoricalProductHolding WHERE ProductId=NA'
  nanodbc/nanodbc.cpp:1587: 42S22: [Microsoft][ODBC SQL Server Driver][SQL Server]Invalid column name 'NA'. 
> 

from pairs.

nassuphis avatar nassuphis commented on July 30, 2024

F3FINS Index does seem to cause the error

from pairs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.