Hello academia community,

I'm writing a paper in Finance on Portfolio optimization and stock returns. For this, I'm using R code to compute optimal portfolio allocation, histograms, boxplots etc.

My supervisor told me to include the R code including documentation, however I'm not sure what this means. I included all figures and tables computed by R in the appendix, but I'm not sure if I should include the R code as it is rather simple code that I wrote, most of it graphic parameters or simple formulas taken from packages (whose authors I already included). Should I attach the 800 lines of code at then end of the appendix, or should I just upload it to a website such as GitHub? My R code also takes in raw data from excel files; what should I do about those?

I can only upload pdf files to my university server when submitting the thesis for review.

  • 3
    This is becoming pretty standard across numerous fields in academia. I have found that it has made me a better coder. Not in terms of functionality but in presentation. For example, I am far more likely to use piping now that others will be reading my code. As for what you do, just load it to your github and put a link to it in your abstract.
    – JWH2006
    Aug 22, 2018 at 11:41
  • If you use LaTeX, you can have your code auto-coloured and nicely formatted with the listings package anywhere in the document. - Also, even short messy code can be better than no code which then leaves the future reader wondering about how a result was achieved.
    – DetlevCM
    Aug 23, 2018 at 6:59

1 Answer 1


Welcome to Academia.

It sounds like your supervisor has required you to include the 800 lines of (simple) code that you've written to perform the analysis and data visualisation in your manuscript. This is not necessarily a strange request. I, myself, require it of my students as an addendum or appendix to their work. I don't include the code it in any word count limits that I impose. You should ask your supervisor if you could upload the work onto GitHub or some other site. Policies vary, so you need to check. Finally, depending on the sensitivity of your data, the content of the Excel files may contain sensitive information that requires permissions from data owners or even the Ethics Committee before you distribute them, so be careful about that.

When you include the code, I suggest that you make sure that you've cleaned the code and have used comments strategically. I suggest that you use R Markdown for better effect.

For more technical statistical help, you might want to refer to Academia's sister site for statistics, Cross Validated. For programming help, head to Stack Overflow.

Good luck to you.

  • Wow, quick reply. The excel files only contain closing prices of stocks for a time period of 5 years. So I think I'm safe to include them.
    – PrinzvonK
    Aug 22, 2018 at 10:18
  • 1
    Make sure the data aren't proprietary. For example, some of the Reuters stuff might require special permissions. Ask your data librarian.
    – user96258
    Aug 22, 2018 at 10:20
  • My stock data came from the quantmod package with the getSymbols command. I then sliced it to only show closing prices, adjusted closing prices and dividends.
    – PrinzvonK
    Aug 22, 2018 at 10:22
  • Ahh. Shouldn't be a problem, then.
    – user96258
    Aug 22, 2018 at 10:22
  • 1
    Was going to post but this has everything. Will say that reviewers for my publications have been asking for code via GitHub more often (same field as yours). I've also seen students put code in an Appendix for their archived thesis. Both support follow-on readership and reproducibility. Aug 22, 2018 at 14:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .