I've been optimizing various aspects of my investment setup recently, and will write up some tips and tricks that I've found in the form of "answers" here. Others are welcome to share their own here if they'd like. (Disclaimer: I’m not a lawyer, accountant, or investment advisor, and everything here is for general informational purposes only.)
Farming capital losses by "pre-leveraging"
Suppose you plan to eventually have X exposure (e.g., 200% or 2x leveraged) to the stock market, but currently want Y<X exposure (e.g., 20%) due to market conditions. Instead of buying Y stocks, buy X and hedge it with a X-Y (e.g., 180%) short position (again not using the exact same underlying asset). This way, if the stock market has risen when you're ready for X exposure, you can close the short position to realize a capital loss. Or if the stock market drops during this time, you can sell the long asset and replace it with a substitute (e.g., ITOT for VTI) and again realize a capital loss. The capital loss can be used to offset your current year capital gains, your future capital gains, or even your regular income (up to $3000 per year).
The flip side of this is that the asset you've bought will have a lower cost basis than it otherwise would, which means you'll have a higher capital gain tax when you sell it, but you might never sell it (it might go into your estate or you might donate it) in which case no capital gains will be realized, and even if you do sell it, the IRS has essentially given you an interest-free loan for the intervening years.
I've been using MaxMyInterest since 2015. They list out the highest-interest FDIC-insured savings accounts and make it easy to open them and transfer money between them. They'll also automatically track which of your savings accounts has the highest interest rate (if you have more than one) and move your money there. (Or if you have so much money that you exceed the FDIC limit ... which somehow has never been a problem for me! ... it can split your money into multiple accounts to get around that.) It also links with your low-interest everyday checking account, and will periodically transfer money back and forth to keep the latter balance at whatever amount you tell it. I really like that last feature, it saves me time and mental energy. They charge a fee of (currently) 0.08%/year × however much money you have in the high-interest savings accounts.
References/tools for portfolio optimization
Use options or futures to avoid realizing capital gains
When you want to reduce exposure to some market but don't want to sell your assets due to tax considerations, you can make a nearly opposite bet with options or futures to neutralize your exposure. "Nearly" is important because the IRS will consider you to have sold your assets if you make an exactly opposite bet, e.g., synthetic short via options with the same underlying asset as what you're holding. See https://www.cmegroup.com/education/whitepapers/hedging-with-e-mini-sp-500-future.html and https://www.optionseducation.org/strategies/all-strategies/synthetic-short-stock.
Leverage methods and their tax considerations
Negotiate with your brokers
A lot of brokerages will pay you cash bonuses to transfer your assets to them (and typically keep them there for a year) and this is another source of extra risk-free return. These public offers are usually capped at $2500 bonus for $1M of assets, but some places will give you $2500 per $1M of assets, plus deep discounts on futures/options commissions and margin rates. (You can PM or email me to get details and contact info of the brokerage representatives I've talked with.)
Reduce exposure/leverage during market volatility
During periods of high market volatility, the expected return of the stock market probably doesn't compensate for the increased risk. See https://www.facebook.com/bshlgrs/posts/10219080184370250?comment_id=10219085165454774 for a discussion of this. (Facebook comment linking seems to be broken at the moment, see discussion under the first comment by Carl Shulman.)
Box spread financing (borrow for 3 years at around 0.55% interest rate currently)
With box spread financing, you can borrow for up to 3 years at a fixed rate about 30bp (.3%) above the corresponding treasury yield. Someone may post a more detailed article about this later, but in the meantime see https://www.reddit.com/r/wallstreetbets/comments/fegqz0/box_spread_financing_for_extremely_cheap_085/ and https://www.theocc.com/components/docs/about/press/white-papers/2016/box-spreads-options-strategies-for-borrowing-or-lending-cash.pdf
Bankruptcy risk for a leveraged portfolio
From Brian Tomasik's Should Altruists Leverage Investments?
Also note that this continuous-time model doesn't allow margin accounts to go bankrupt. Because a continuous-time margin account maintains constant leverage, if its assets fall, it rebalances immediately by selling some securities. In the real world, margin accounts can go bankrupt. This could, with low probability, even happen if the account rebalances daily. For instance, a 5X-leveraged margin account that rebalanced once per day might have been wiped out by 1987's Black Monday. By not allowing for bankruptcy (and by ignoring black swans in general), continuous-time equations like those above may slightly overstate the expected value of leverage. In the extreme case, taking t = ∞, a margin investor who doesn't rebalance continuously would go bankrupt with probability 1 (since eventually there would be a huge, near-instantaneous market downturn that destroys the account), while the leveraged mean equation concludes that the margin investor ends up with infinite expected wealth.
One might think that rebalancing more frequently than daily would help (perhaps with the help of an algorithm), but you can't rebalance when markets are closed, e.g., during weekends. I haven't figured out the best way to mitigate this risk yet (which isn't really so much about bankruptcy as being over-leveraged when asset values fall too much before you're able to rebalance), but two ideas are (1) keep some put options in one's portfolio, and (2) have some assets that are protected during bankruptcy (e.g., retirement accounts, spendthrift trusts).
Portfolio margin allows higher leverage and lets you "net" positions against each other for the purposes of determining margin requirements. E.g., you can be 10x long VTI and 10x short SPX via options, and have only a small margin requirement. This allows some of the other tips/tricks to work.
Not all brokerages offer this, but I know E*TRADE, TD Ameritrade, and Interactive Brokers do. And you do have to apply for it and pass a test or interview to show that you understand what you're getting into.
Using CDs / Savings Accounts for extra risk-free return
With portfolio margin, you can easily find yourself with more available leverage than you want to use, i.e., in the form of extra "buying power" or "equity". Instead of letting that go to waste, you can withdraw some of your extra equity (and cover that with margin loan or box spread financing) and put that cash into an FDIC-insured savings account or CD, which currently yield 1% higher than the borrowing cost. Here's my explanation of why this "free lunch" is possible:
I've been wondering why some banks (e.g., Goldman Sachs's Marcus, Ally Bank) pay customers 1.5% interest on their savings account, when other interest rates are so much lower. (Withdrawing excess "equity" from my margin account and putting it into such a savings account is another way to make extra risk-free returns, currently 1% per year which seems amazing when you consider that 3-year treasuries are at .25%.) From Goldman Sachs's annual report, "These deposits include savings and time deposits which provide us with a diversified source of funding that reduces our reliance on wholesale funding." From other sources it seems that wholesale funding is less reliable in economic crashes, when wholesale interest rates could spike for banks that are deemed risky by the market, whereas retail customers are more likely to stick with banks they're used to, since their deposits are insured.
So it seems like as long as the federal government continues to subsidize savers and banks (by implicitly backing the FDIC), this extra return should be available.
ETA: See also Are There Ways to Maximize FDIC Insurance Coverage?
Pay your monthly bills with margin loans
Instead of maintaining a positive balance in a bank checking account that pays virtually no interest and having to worry about overdrafts, switch your bill payment to a brokerage account that offers low margin rates, and pay your bills "on margin". (Interactive Brokers currently offers 1.55% (for loans <$100k), or negotiate with your current broker (I got 0.75% starting at the first dollar)). Once a while, sell some securities, move money back from a high yield savings account or CD, or get cash from box spread financing, to zero out the margin balance.
If you're investing to donate, consider using a tax-deductible entity
If you ultimately want to give, you can get ~1% extra per year by using a tax-deductible entity.
In the UK, it's a substantial effort to set up a charity, but you have a lot of freedom with respect to how you invest, so you can also implement relatively advanced strategies.
In Switzerland, the effort of setting up a charity is very small, but you do face some limitations on investment options.
I haven't looked into other jurisdictions.