# file: makefile
# author: Bernt A Oedegaard

## uncomment if you have available my term structure class
##DEFS += -D_HAVE_TERM_STRUCTURE_CLASS_

## uncomment if you have installed the NEWMAT09 matrix class 
##DEFS += -D_HAVE_NEWMAT_

CXX = g++ $(DEFS)
ZIPFILE = sources.zip

HXXFILES = normdist.h fin_algoritms.h random.h knuthran.h 
CXXFILES = \
   cflow_irr.cc cflow_irr_test_unique.cc cflow_pv.cc cflow_pv_discrete.cc \
   mv_calc_port_constrained.cc mv_calc_port_no_shortsales.cc mv_calc_port_unconstrained.cc mv_calc.cc \
   black_scholes_call.cc black_scholes_call_div.cc \
   black_scholes_delta_call.cc black_scholes_delta_put.cc \
   black_scholes_imp_vol_bisect.cc black_scholes_imp_vol_newt.cc \
   black_scholes_partials_call.cc black_scholes_partials_put.cc \
   black_scholes_price_payout_call.cc  black_scholes_price_payout_put.cc \
   black_scholes_put.cc black_scholes_put_div.cc \
   anal_price_am_call_div.cc \
   bin_am_call.cc bin_am_div_call.cc bin_am_prop_div_call.cc bin_eur_call.cc \
   bin_am_put.cc  bin_am_div_put.cc  bin_am_prop_div_put.cc  bin_eur_put.cc \
   bin_am_delta_call.cc bin_am_delta_put.cc \
   bin_am_partials_call.cc bin_am_partials_put.cc \
   findiff_exp_am_call.cc findiff_exp_am_put.cc\
   findiff_exp_eur_call.cc findiff_exp_eur_put.cc \
   findiff_imp_am_call.cc findiff_imp_am_put.cc\
   findiff_imp_eur_call.cc findiff_imp_eur_put.cc \
   simulated_call_euro.cc simulated_put_euro.cc \
   simulated_delta_call.cc simulated_delta_put.cc \
   approx_am_call.cc approx_am_put.cc \
   currency_opt_bin_call.cc currency_opt_bin_put.cc \
   currency_opt_euro_call.cc currency_opt_euro_put.cc \
   futures_opt_call_bin.cc futures_opt_call_black.cc \
   futures_opt_put_bin.cc futures_opt_put_black.cc \
   futures_price.cc \
   bonds_convexity.cc bonds_duration.cc bonds_duration_macaulay.cc \
   bonds_price.cc bonds_yield.cc bonds_price_both.cc bonds_price_discrete.cc \
   bonds_duration_modified.cc bonds_duration_modified_termstru.cc \
   bonds_duration_termstru.cc bonds_price_termstru.cc \
   exotics_lookback_call.cc  exotics_lookback_put.cc \
      simulate_general.cc simulate_general_control_variate.cc  \
      simulate_general_payoff_average.cc simulate_general_payoff_bs.cc \
      simulate_general_payoff_min_max.cc simulate_general_underlying_sequence.cc\
      simulate_general_underlying_terminal.cc \
   termstru_transforms.cc  termstru_discfact_cubic_spline.cc  \
   termstru_discfact_cir.cc termstru_discfact_estimated_cir.cc \
   termstru_discfact_vasicek.cc termstru_yield_bliss.cc \
   termstru_yield_interpolated.cc termstru_yield_nels_sie.cc \
   bondopt_call_bs.cc bondopt_call_coupon_bs.cc \
   bondopt_put_bs.cc bondopt_put_coupon_bs.cc \
   bondopt_call_vasicek.cc bondopt_put_vasicek.cc \
   bondopt_call_rend_bart.cc \
   merton_jump_diff_call.cc \
   normdist.cc random.cc knuthran.cc 
TSTFILES = tst.cc \
           tst_cash_flow.cc \
           tst_black_scholes.cc tst_binomial.cc tst_finite_diff.cc \
           tst_simulate.cc tst_approximate.cc \
           tst_futures.cc tst_currency.cc \
           tst_bonds.cc \
           tst_exotics.cc \
           tst_simulate_general.cc \
           tst_term_structure.cc \
           tst_bondopt_black_scholes.cc \
           tst_bondopt_rend_bart.cc \
           tst_bondopt_vasicek.cc \
           tst_alternative_formulas.cc \
           tst_normal.cc tst_random.cc
ALLFILES = readme makefile $(CXXFILES) $(HXXFILES)  $(TSTFILES)

OBJS =  \
   cflow_irr.o cflow_irr_test_unique.o cflow_pv.o cflow_pv_discrete.o \
   black_scholes_call.o black_scholes_call_div.o \
   black_scholes_delta_call.o black_scholes_delta_put.o \
   black_scholes_imp_vol_bisect.o black_scholes_imp_vol_newt.o \
   black_scholes_partials_call.o black_scholes_partials_put.o \
   black_scholes_price_payout_call.o  black_scholes_price_payout_put.o \
   black_scholes_put.o black_scholes_put_div.o \
   anal_price_am_call_div.o \
   bin_am_call.o bin_am_div_call.o bin_am_prop_div_call.o bin_eur_call.o \
       bin_am_put.o bin_am_div_put.o bin_am_prop_div_put.o bin_eur_put.o \
       bin_am_delta_call.o bin_am_delta_put.o \
       bin_am_partials_call.o bin_am_partials_put.o \
       findiff_exp_am_call.o findiff_exp_am_put.o \
       findiff_exp_eur_call.o findiff_exp_eur_put.o \
       simulated_call_euro.o simulated_put_euro.o \
       simulated_delta_call.o simulated_delta_put.o \
       approx_am_call.o approx_am_put.o \
       merton_jump_diff_call.o \
       currency_opt_bin_call.o currency_opt_bin_put.o \
       currency_opt_euro_call.o currency_opt_euro_put.o \
       futures_opt_call_bin.o futures_opt_call_black.o \
       futures_opt_put_bin.o futures_opt_put_black.o \
       futures_price.o \
       bonds_price.o bonds_convexity.o bonds_duration.o \
       bonds_duration_macaulay.o bonds_yield.o \
      bonds_price_discrete.o bonds_duration_modified.o bonds_price_both.o \
       exotics_lookback_call.o exotics_lookback_put.o \
      simulate_general.o simulate_general_control_variate.o  \
      simulate_general_payoff_average.o simulate_general_payoff_bs.o \
      simulate_general_payoff_min_max.o simulate_general_underlying_sequence.o\
      simulate_general_underlying_terminal.o \
   termstru_transforms.o  termstru_discfact_cubic_spline.o  \
   termstru_discfact_cir.o termstru_discfact_estimated_cir.o \
   termstru_discfact_vasicek.o termstru_yield_bliss.o \
   termstru_yield_interpolated.o termstru_yield_nels_sie.o \
   bondopt_call_bs.o bondopt_call_coupon_bs.o \
   bondopt_put_bs.o bondopt_put_coupon_bs.o \
   bondopt_call_rend_bart.o \
   bondopt_call_vasicek.o bondopt_put_vasicek.o \
       normdist.o random.o knuthran.o

### uncomment if have NEWMAT matrix library
#OBJS +=  findiff_imp_am_call.o findiff_imp_am_put.o \
#       findiff_imp_eur_call.o findiff_imp_eur_put.o \
### uncomment if have term structure class
#OBJS += bonds_duration_modified_termstru.o bonds_duration_termstru.o \
#        bonds_price_termstru.o

LIB = libfinalgo.a
$(LIB): $(OBJS) 
	ar ur $(LIB) $(OBJS) 
	ranlib $(LIB)
tst.o: $(TSTFILES) fin_algoritms.h 
tst: tst.o $(LIB)
	$(CXX) tst.o $(LIBS) -o tst -lm 
LIBS = -lfinalgo
algoritms.zip: $(ALLFILES)
	zip -u algoritms.zip $(ALLFILES)

##### ignore below ###########################
#CXX = g++ -I$(INCDIR) $(DEFS)
#LIBS =  -L. -lfinalgo -L$(LIBDIR) -lnewmat -ldstru  
INCDIR = $(HOME)/include
LIBDIR = $(HOME)/lib
WWWDIR = $(HOME)/public_html/gcc_prog/algoritms
sources.zip: fin_algoritms.h makefile readme tst.cc
	zip -u sources.zip makefile readme fin_algoritms.h tst.cc
install: install-h install-www
install-h: 
	cp fin_algoritms.h $(INCDIR)
install-www: algoritms.zip
	cp algoritms.zip $(WWWDIR)
install-lib:
install-doc:
install-src:
pack:  sources.zip
clean:
	rm -f  lib*.a tst *.o *~
realclean: clean
unpack:
	unzip -u -o sources 
crunch: realclean sources.zip
	zip -u -m sources.zip fin_algoritms.h tst.cc readme
	zip -um algoritms.zip $(CXXFILES) $(TSTFILES) knuthran.h random.h normdist.h 
	rm -f algoritms.zip
